Alexa Metrics

Programming Languages Series: JavaScript for beginners Variables in JavaScript


JavaScript is one of the most widely used programming languages of the Web. JavaScript is very widely spread due to its easy syntax. We will spot the light on some of its programming concepts and syntax to get you familiar with the language before taking a dive into programming.

The Beginner level will start with Variables:

Definition of Variables:

Variables in programming are value containers. You can store whatever value you have in a variable. When you create a variable in a programming language, it is called “declaring”.

Variables Declaration:

In JavaScript, a variable is declared using the keyword var, for instance, if you want to declare a variable x, you shall say "var x;".

Make sure you include a semicolon at the end of every sentence unlike Python where you shall not.

Undefined Variables:

After variable declaration, variables usually have no value. So they have what is called undefined which means they have no defined value till now. So, whenever you use a variable with undefined value in an operation, you shall get an error.

Storing in a Variable:

Storing a value in a variable is called assignment operation. This happens when you append an equal sign after the variable declaration and then storing whatever you need to store.

For instance “var x = 3;”. You can declare as many variables in one statement as you want. You just start with the var keyword and separate the different variables by using commas.

Whenever you re-declare a variable in JavaScript, it will keep the previous value and will not be rewritten.


All variables in JavaScript have to be identified with unique names called identifiers. Identifiers can be letters or whole words like x, y or sum, product. But always bear in mind that variable names must begin with a letter, a dollar sign or an underscore only, they can contain letters, digits, underscores afterwards, but always start with one of the former. Variable names in JavaScript are case sensitive, means Age and age are treated as 2 different variables.

Variables Type:

When you declare a variable and sign a value to it, the variable type is copied from the type of the value assigned. For instance var x = 2; will make x an integer type while var x = “Tom” will make x a string variable, a variable type that holds character lists. JavaScript can handle many types of data. Strings are written inside double or single quotes while numbers are written without quotes.

Got excited and want to start writing code. Try Robogarden JavaScript Journeys now.

JavaScript Series Introduction to JavaScript


Start JavaScript coding

Let's start JavaScript coding with RoboGarden learning journey.

Canada Flag Privacy Policy Terms of Use
Got an invite