Javascript data types

Tut#2 JavaScript Variables

What do we discuss in this article?

  1. Variables

A] Variables

1)Variable Without value

In JavaScript, a variable can hold any type of data. To define a variable, use the var keyword followed by the variable name which is an identifier which we discussed in the previous post.

2)Variable with value

At this point, the variable myText can contain any type of value. But since we have not specified any value for it explicitly, it takes up a special value undefined. which we’ll discuss shortly.

However, here we have made a variable called myText that contains the value “Vivz” which is known as a String in JavaScript or [set of characters or word in English].

Doing this initialization doesn’t mark the variable as being a string type; it is simply the assignment of a value to the variable. It is still possible to not only change the value stored in the variable but also change the type of value as shown below.

Switching the type of data stored in a variable is perfectly valid but not recommended.

3)Multiple Variables

Notice how, multiple variables have been declared on the same line. Notice how each variable has its value and is separated with a comma from the previous or next variable and ultimately everything is terminated with a semicolon. Variable initializations using different data types may be combined into a single statement.


Don’t let the jargon and technical terms overload you. Once a few basic things are covered, you are well on your way to become a full-fledged JavaScript developer. In the meantime, let “Intelligence Be Your Only Keyword”.