javascript 1 min read

Lesson 4 -- Variables (Advanced)

In this lesson, we will learn about the Types of Variables and how to use and manipulate them.

In this lesson, we will learn about the Types of Variables and how to use and manipulate them. In case you skipped or missed the last lesson about Introduction to Variables, please check it out first as I will assume you are well versed with the concept of Variables for this lesson.

So, let’s see the types of Variables we can use by analysing the following code:

Code:

Output:

Now, let’s look up the explanation of All types of Variables one by one:

  1. Integer (INT): As the name suggests, It is used to store the value of an Integer number (like 12,4,6..).
  2. Float: It is also used to store a Number but with Decimal structure (like 0.02, 0.6, 13.5..).
  3. String: A string is a variable which stores a series of characters like “John Doe”. Strings are written with quotes.
  4. Boolean: Booleans can only have two values: true or false. They are generally used as Flags/Switch.
  5. Null: The value of a variable with no value is undefined. Variables can be emptied by setting the value to null. Note: Null is not equal to Zero (0).

So, here we go. This lesson was to make you understand different types of Variables and how to use them.

#DIY-1

Now I have a DIY(Do-it-yourself) for you guys. I want you to write the code to print out an exciting Story using all the types of variables. It can be any story from a fictional one to your own personal experience. You can post the following in the comment section.

Once you are comfortable with your understanding of Different types of variables in JavaScript, you can move on to the next lesson where we will learn how to use both the strings and variables together in a single statement. Till then, See you guys.

Leave a comment

Keep reading