02Geek HTML5 and JavaScript, TypeScript, React, Flash, ActionScript online School
Previous VideoPrevious Video

Logical Operator

We are already familiar with Rational Operators, Equality Operators and Explicit Equality Operators. Now it is time to learn Logical Operators. You will understand this easily if you are familiar with the words AND, OR, NAND, NOR, NOT etc. However, there is nothing to worry about even if you are new to these words as we'll discuss everything in detail about the logical operators. In this video we are going to discuss two important logical operators which are commonly used in programming. The first of it is AND, represented by the symbol (&&) and the second is OR, represented by the symbol (||).

AND (&&) Logical Operator

The first thing to remember is that this operator is represented by the double ampersand (&&) and not the single ampersand (&). Most people make a mistake here by just typing one ampersand instead of two. So keep in mind that the AND logical Operator is represented by (&&). Now, let's move to the concept of equality once again before we start with the (&&) operator.

In the above exercises, we compared an equation for either equality or inequality. It was very easy to compare any two values. But the problem arises when the equation has more than two variables or when we need to compare more than two equations at a time. To overcome this problem, we use Logical Operators along with the Rational and Equality Operators. For example if we need to compare two equations say c>a and c<b at a time, we can write this equation as trace(c>a && c<b). Now the output is given as true only if both conditions are met: c>a as well as c>b. If either one of the two is false or both are false, the result is given as false. Therefore, && is a logical operators which turns on (true) only if both the conditions are true and not in any other case.

OR (||) Logical Operator

We have seen the need for logical operators in the AND logical operator section, so we won't go deeply into why we need to use the OR logical operator. Just a few important things to note here: first the OR logical Operator is represented by the symbol (||). Secondly, when we use logical operators between any two equations, the result is true if either one of the two statements is true or when both statements are true. For example, if we consider the same example with (||) Operator trace(c>a || c<b), the result is true if at least one of them is true -- or the result is false only when both statements are false. Initially, the compiler checks for the first equation: if it's true then the second equation is not evaluated and the result is given as true. But if the first one is false, the compiler then checks the second equation and gives the result depending on the trueness of the second statement.

Overview

What are operators and why do we need them to create programs. We'll discuss various types of operators and their uses later in this course

01:49

Default Values

To understand operators, we first need to understand how variables work -- mainly when it comes to default values and why they differ for various variable types.

06:41

Equality

In this video we will compare between equality and assignment and learn how to work with both. We also differentiate between the assignment operator (=) and the equality operator (==)

06:40

Rational Operators

In this video we will see how to check if a variable is: bigger, smaller, greater or equals, smaller or equals and so on..... using rational operators

05:52

From Rational to Boolean

All the operators we worked with so far returned in our trace panel a value of true or false. In this video we'll see that connection of our operators results to the Boolean data type as we explore

05:26

Equality Operators

So far we've seen how to compare and see if values differ or match but we did not have a way to ask if not. In this sample we'll look into the equality operator(make it a bit more complex)

05:59

Comparison Between Different Types

In the heart of programming is the capability to compare between things. In this video we talk about comparing between different variable data types.

04:15

Explicit Equality

Sometimes knowing if something is equal just isn't enough and we need to know if it is explicitly equal and that's where explicit equality operator comes in...

08:05

Logical Operator

Logical operators enable us to compare a few things at a time such as AND, OR and NOT. We will learn the syntax to represent these operators using few examples

09:52

There Are Many Ways To Say No

doing exactly the oposite of the logical logic seams crazy but actually its a very great way to get things done. Let us learn how to say no in terms of programming

04:15

Null vs. Undefined

Why are there two ways of saying nothing? I ponder that as well as I try to explain their roles. In the process, we will learn the syntax and its application in code

06:20