Defining Variables
You use variables in JavaScript to temporarily store and access data from your JavaScript files. Variables can point to simple data types such as numbers or strings, or they can point to more complex data types such as objects.
To define a variable in JavaScript, you use the var keyword and then give the variable a name, as in this example:
var myData;
You can also assign a value to the variable in the same line. For example, the following line of code creates a variable myString and assigns it the value "Some Text":
var myString = "Some Text";
This single line does the same thing as the following two lines:
var myString;myString = "Some Text";
After you have declared a variable, you can use its name to assign a value to the ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access