my name is george phillips and i am a freelance web developer based in london

blog

Declaring a JavaScript Variable

To declare a JavaScript variable, type the keyword var. This is a variable declaration.

To declare a variable called yourName type var yourName. The space between var and yourName has to be there.

What this does is, it creates an undefinded or empty variable called yourName which is ready to be assigned or point to a value.

To assign a value to your variable, use the assignment operator =.

To declare more than one variable, you only need to type the var keyword once and separate declarations with a comma. var varOne = "some value", varTwo = "another value";

  • Variables cannot start with a number.
  • Can start with $, _ or letter.
  • They are case sensitive
  • Can continue with $, _, letter or number

This is a JavaScript Statement
var foo = true, baz = false;
JavaScript statements end in a semi-colon ;

Leave a Reply