Tuesday, February 10, 2015

JavaScript Variables,declaration and use

JavaScript Variables:



 Variables are containers that you can store values in. You start by declaring a variable with the var keyword, followed by any name you want to call it:

var myVar;

All lines in JS must end with a semi-colon, to indicate that this is where the line ends. If you don't include these, you can get unexpected results.

You can call a variable nearly anything, but there are some name restrictions.

JavaScript is case sensitive — myVar is a different variable to myvar. If you are getting problems in your code, check the casing.

After declaring a variable, you can give it a value of declared javascript variable:

myVar = 'deep';

You can retrieve the value by just calling the variable by name:

myVar;

You can do both these operations on the same line if you wish:




No comments:

Post a Comment