JavaScript Variables

JavaScript Variables

Written

Many JavaScripts deal with variables. This is where you take a word or letter and assign a value to it. The value can be either numbers or words. To think of it in physical terms, imagine a box with a label stuck on it and there is a piece of paper with a name or number written on it inside the box. The labeled box is a variable, and the name or number on the paper is the value.

Look horribly familiar? It's the stuff you learn in school and think to yourself "When will I EVER need to know algebra in real life ?". Well... here it is.

You can use strings (regular text) instead of numbers in these equations too. Or a number and a string.

Other than the usual assignment operators + - / * = you can use JavaScript to compare two or more variables with each other. That is, it takes two values and compares them to each other. Here is a list of the different types of comparisons there are:

As stated before, part of having a numeric value in variables lets you use regular math expressions on them like so...

Table of Contents