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

Default Values

<h2>Default Values</h2> <p>We know how to declare a <a href="/courses/video/5/157/Using-Variables.html">variable</a> and assign a value to it. Have you ever wondered what happens if we declare a variable and don't assign any value to it? In this case, the application has to reserve memory for the variable, irrespective of whether the value is assigned or not. The memory size depends upon the <a href="/courses/video/5/161/Numbers-int-And-unit.html">type of variable</a> declared. This memory location will be occupied by the value we assign later. If we don't assign any value and proceed to the next command, the compiler saves a default value for that memory space. All such values assigned by the application are termed as default values.</p> <h2>Default values for different <a href="/courses/video/5/161/Numbers-int-And-unit.html">data types</a></h2> <p>Let's see how the application assigns values for different types of data. When we declare a variable of type <a href="/courses/video/4/154/Strings-As-Our-First-Variable.html">string</a>, for example var str:String; the default value for this variable is <a href="/courses/video/7/60/Null-vs-Undefined.html">nothing -- or null</a>. Since we didn't assign a value to str, no memory is assigned to it. Similarly with a <a href="/courses/video/4/156/Numbers-As-Our-Second-Variable.html">Number</a>, the default value that is assigned is NAN (not a number). But an int has a set of values: Z= {...-3.-2,-1, 0, 1, 2,....} and <a href="/courses/video/5/161/Numbers-int-And-unit.html">uint</a> has all the positive integers {0, 1, 2, ...}. For these data types, the empty value or the default value is zero. Finally, for a <a href="/courses/video/5/162/Boolean.html">Boolean</a> data type, there are only two possible values: true or false. The value closest to nothing in this case is false. It's not exactly equal to null, but the nearest value to nothing among the two is definitely false. So, the application assigns false as the Boolean variable default.</p> <h2>Assign values to all the variables manually</h2> <p>When we trace these <a href="/courses/video/5/157/Using-Variables.html">variables</a>, we can find the above mentioned default values in the output panel. But when we depend on defaults (lazy behavior!) in big programs, this might cause confusion. So to avoid any difficulty, we must always assign a value to the variable soon after it's declared. Even if we want the variable to be empty, we should assign some value which is considered as <a href="/courses/video/7/60/Null-vs-Undefined.html">nothing</a>. For example, assign 0 to an <a href="/courses/video/5/161/Numbers-int-And-unit.html">int or uint</a>, instead of asking the compiler to assign the default values. There's a good reason for this: various applications have their own default values and we might get confused when we switch to another application. To be on the safe side, we should always assign a value to a variable manually as soon as it is declared.</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