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

Null vs. Undefined

<p>We have learned the concept of nothing earlier, but did you realize there are two different types of nothing? Here we'll look at both. When we define a <a href="/courses/video/5/157/Using-Variables.html">variable</a> along with a <a href="/courses/video/5/161/Numbers-int-And-unit.html">data type</a> but don't assign any value to it, then the variable is empty. What does <b>empty</b> actually mean? Such a variable has nothing in it and is referred to as null. A memory location is defined for this variable, depending upon its data type. This is definitely a defined variable but with no real content: in other words it's undefined.</p> <h2>Undefined</h2> <p>So if a null variable is empty or has nothing in it, then what about an undefined one? If we declare a variable and don't even mention the data type for it, then such a variable is called <b>undefined</b>. Even though it has nothing in it like null, this variable has no memory defined for it. The compiler defines memory for only those variables whose data type is assigned. We can say that a declared variable with no <a href="/courses/video/5/161/Numbers-int-And-unit.html">data type</a> is considered as an <b>Undefined Variable</b>.</p> <h2>Comparing null and Undefined</h2> <p>There is a difference between these two, but both of them are basically nothing. If we try to equate these two terms, the result would be true along with a warning that the comparison is not substantial. However, if we try to compare these two for <a href="/courses/video/7/199/Explicit-Equality.html">explicit equality</a>, the result would now be false with two warnings. This is because these are two different types of nothing (null and undefined) and are therefore not <a href="/courses/video/7/199/Explicit-Equality.html">explicitly</a> equal.</p> <h2>Comparing null and Undefined variables</h2> <p>Let's declare a <a href="/courses/video/5/157/Using-Variables.html">variable</a> <b>var str:String</b>; No value is assigned to str, so it is null. If we write <b>trace(str==null)</b>, the result would be true. Similarly, if we declare a variable <b>var num</b>; there is no data type associated with it in spite of being empty. Now if we write <b>trace(num==Undefined)</b>, the value would be true. Let's just interchange the variables for these two data types. For example, if we write <b>trace(str==Undefined)</b> or <b>trace(num==null)</b>, the result would still be true as both refer to nothing. But if we try to compare the explicit equality and write <b>trace(num===null)</b>, the result would be false because though both refer to Nothing, they are of different 'nothing' types which means they aren't explicitly equal.</p> <p>Let's now compare only the <a href="/courses/video/5/157/Using-Variables.html">variables</a> without the involvement of the keywords. If we write <b>trace(str==num)</b>or <b>trace(num==str)</b>, the result would be true without any warning. When we compare <b>trace(str===num)</b> or <b>trace(num===str)</b>, the result would now be false without any warning showing that they are <a href="/courses/video/7/199/Explicit-Equality.html">explicitly</a> unequal. This shows that there is no warning generated if we compare only the <a href="/courses/video/5/157/Using-Variables.html">variables</a> without using keywords. Further, if we don't want the compiler to generate any error or a warning for Undefined Variables, we have to declare the variable along with * symbol in the following way, <b>var str: *</b>; The application then comes to know that the variable in not defined intentionally.</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