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

Comparison Between Different Types

What happens when you compare different data types in Flash? In this video we'll go over some of the basic operations when comparing different date types. The most valuable lesson you can take from this video is how Flash deals with such a comparison when working with a regular comparison operator(’==' and '!='.)

In this course, we have compared different variables of the same data type. We used a number of rational and equality operators to compare the variables or values which are of same type. Now we'll see how to compare the variables of different data types.

Let us declare a variable 'a' with type int and a variable 'b' with data type number. Let the value be a=1 and b=2 which satisfies the respective data types. Now we can use trace(a==b) to check whether these two values are equal. If yes, you get true or else false. Here we can see that the two values are not equal and hence, the output is false. However, if we use trace(a!=b), the result would be true because the comparison now is for inequality and the condition for inequality is met as the values are unequal. This was explained earlier too but now it is a kind of revision for us.

You might think, comparing variables of type int with type Number is well and good, but what if the comparison is to be done between type int and type Boolean (or type number and type Boolean?) We are going to discuss this here. We can explain this with the help of an example. Let's have variables a:int and b:Number . Assume that a=1 and b=0. Let's assign a Boolean variable now with value true:

var isTrue:Boolean = true;

We can say trace(isTrue) is true. If the value assigned to it is false then we get trace(isTrue) as false. Here we need to remember one thing that, a true value is considered to be 1 and a false value is considered to be 0 as said in the earlier videos.

So now we have a=1,b=0 and isTrue = true (=1). If we try to compare int and Boolean variables we have trace(a==isTrue), this will result as true. If we compare number type and Boolean type that is trace(b==isTrue), the result will be false because b=0 and isTrue=1 as it is true. Similarly, if isTrue is false then the value of isTrue=0, the results will now take a reverse shift.

We have compared variables of different types whose value is either 0 or 1. But if the value of integer variable a is 5, and if we trace(a==isTrue), the result would be false for both Boolean values (true or false) which is equal to 0 or 1. Neither 0 or 1 is equal to 5; the output will be false every time. In fact if we use the command trace(a!=isTrue), the result would be true as it satisfies the inequality.

One more key point we can take from this video is never use keywords as variables! We know that we can use any letter or word for a variable name but there are a few exceptions here as well. Data types and a few other keywords are already defined by the developers and are stored in the library for specific use. Therefore, usage of such keywords as variables in our program can cause problems. Hence, make sure that the variables declared don't match with any of the keywords.

Ready to Level Up Your Skills?

Join thousands of learners on 02GEEK and start your journey to becoming a coding expert today!

Enroll Now for Free!

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