O'Reilly logo

JavaScript Quick Syntax Reference by Mikael Olsson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

CHAPTER 2

image

Variables

Variables are containers used for storing data, such as numbers or strings, so that they can be used multiple times in a script.

Declaring Variables

To create a variable the var keyword is used followed by a name, called the identifier. A common naming convention for variables is to have each word initially capitalized, except for the first one.

var myVar;

A value can be assigned to a variable by using the equals sign, which is called the assignment operator (=). This is called assigning or initializing the variable.

myVar = 10;

The declaration and assignment can be combined into a single statement. When a variable is assigned ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required