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

Logical Operator

<p>We are already familiar with <a href="/courses/video/7/56/Rational-Operators.html">Rational Operators</a>, <a href="/courses/video/7/58/Equality-Operators.html">Equality Operators</a> and <a href="/courses/video/7/199/Explicit-Equality.html">Explicit Equality</a> 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 (&amp;&amp;) and the second is OR, represented by the symbol (||).</p> <h2>AND (&amp;&amp;) Logical Operator</h2> <p>The first thing to remember is that this operator is represented by the double ampersand (&amp;&amp;) and not the single ampersand (&amp;). 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 (&amp;&amp;). Now, let's move to the concept of <a href="/courses/video/7/55/Equality.html">equality</a> once again before we start with the (&amp;&amp;) operator.</p> <p>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 <a href="/courses/video/5/157/Using-Variables.html">variables</a> or when we need to compare more than two equations at a time. To overcome this problem, we use Logical Operators along with the <a href="/courses/video/7/56/Rational-Operators.html">Rational</a> and <a href="/courses/video/7/58/Equality-Operators.html">Equality</a> Operators. For example if we need to compare two equations say <b>c&gt;a</b> and <b>c&lt;b</b> at a time, we can write this equation as <b>trace(c&gt;a &amp;&amp; c&lt;b)</b>. Now the output is given as true only if <b>both</b> conditions are met: <b>c&gt;a</b> as well as <b>c&gt;b</b>. If either one of the two is false or both are false, the result is given as false. Therefore, &amp;&amp; is a logical operators which turns on (true) only if both the conditions are true and not in any other case.</p> <h2>OR (||) Logical Operator</h2> <p>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 <b>either one</b> of the two statements is true or when both statements are true. For example, if we consider the same example with (||) Operator <b>trace(c&gt;a || c&lt;b)</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.</p>

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