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

What are Primitives?

<p>We have two <a href="/courses/video/5/157/Using-Variables.html">variables</a> under our belt and it's time we group them into a variable type. This is a critical concept that we will revisit as we learn what <a href="/course/basics/objects">objects</a> are, but for now it's good for us just to understand that we have a different type of variable. A few new topics we are about to learn are dependent upon the logic that this only works for primitive values. (Have no clue what primitive values are, well jump in and let's figure it out!) </p> <p>We can describe primitive variables as the containers that store data for a time. These variables don't preserve large amounts of data to be used later. In other words, we can say that these are <b>instant</b> variables. As said earlier, the concept is clearly understood when compared with objects. Objects are created using classes: these objects are used to store buckets of information at a time. In the case of primitive variables, only <b>one value at a time</b> can be assigned to a primitive variable. If you assign another value to this variable, the variable now contains the new value and the old value is gone. </p> <p>For example let's declare a variable num and assign a value 5 to it: <b>var num:int=5;</b> . Now, according to the definition of this variable, num=5. If we use num in any part of the program, the compiler assumes this as the integer 5. So let's now assign another value, 10, to the same variable num: <b>num=10;</b>. We would expect num to have both the values 5 and 10. But once you assign a new value to a primitive variable, the new value overrides the old value – the variable now contains the new value and not the old one. The variable always contains the most recent value and all the old values are erased. Therefore, these variables are considered as primitive variables. So the value of num is now equal to 10 (num=10.) </p> <p>Now we'll consider another example. If we declare a variable <b>a</b> and assign a value 3 to it, we can say that <b>a=3</b>. In the next line, declare another variable <b>b</b> and assign <b>a</b> to it: </p> <p><i>var a: int = 3;</i></p> <p><i>var b: int = a;</i></p> <p>At first glance, we think <b>b = a</b>, but this is not always the case! In fact, b takes the initial value of a, 3: <b>a=3 then b=a so b now equals 3</b>.</p> <p>For extra credit: later on in your code, you change the value of a: <b>a = 420</b>. What does b equal now? If you said 420, beep! b still equals 3. Primitives hold their initial values until changed: you'd need to add the line <b>b=a;</b> again if you wanted b to have a's NEW value.</p> <p>These types of <a href="/courses/video/5/38/Converting-Strings-to-Numbers.html">conversions</a> are performed with primitive variables. The knowledge of primitive variables is necessary before you start dealing with objects.</p>

Intro

In our mission to learn how to become a developer, things are getting more complicated. We will learn about the importance of variables, brackets, operators and even talk more deeply about data types

01:52

What Opens Must Close

Quick detour - I want to let you in on a little secret. It's my favorite shortcut in the book and will help you manage the many brackets with which you work.

06:33

Addition

Let's study string addition! We will see how we add strings together and how we add numbers together. And if you think that isn't enough, we'll even look at error 1084 and figure out how to avoid it.

03:33

Mixing Strings and Numbers

When working with numbers and strings it's important to prevent Compiler (Flash) from automatically converting data so you'll not be automatically confused.

02:04

Converting Strings to Numbers

How do we take that string and let Flash know we actually want it to be a number? The answer is simple: learn a new function. This function type is called Casting.

01:16

Using Variables

So, we have variables and we know how to create them but how can we actually use them and for what? We agree, it's time to see them in action through this video.

06:15

What are Primitives?

It’s important to differentiate between primitive and complex data types in Flash. Have no clue what primitive values are, well jump in and let's figure it out!

02:09

Deeper Look: Defining Variables

Now that we know what variables are it's time to look deeper into their structure and how to play with them. Also, we'll learn about a new error type we can now check to avoid - Error 1120.

04:10

Deeper Look: Math Operators

Things are starting to fall into the right place! Lets revisit the math operators and add a few new tricks and shortcuts. Also learn about a new operator (%) used to find the modulus of two numbers.

05:36

Numbers, int And unit

Though all three types Number, int and uint are used to represent numbers, there are few minor differences between them which help us save time. Lets learn what are they and when should we use them

07:19

Boolean

Boolean are simple. They are really only place holders that can hold only two possible values: true or false (0 or 1, yes or no...) Lets learn how Boolean variables are used in programming.

01:48