All variables are declared with the 'var' keyword
Variables do not have an explicit data type. There are 3 primitive data types.
Variables do not have a data type until a value is assigned to it and at that point the correct data type is inferred.
The semi-colon is optional when statements are followed by a line break.
var myNumber1 = 10; // number data type
var myNumber2 = 5.38; // number data type
var myString = "text"; // string data type
var myBoolean = false; // boolean data type
var varData = data;
var varName = "Smith";
var varAge = 26;
var isOdd = false;
All On One Line
The semi-colon is required when you have two or more statements on the same line.
This line creates 3 variables and assigns them values
var myObject = new Object(), myString = 'sometext', myNumber = math.random();
If the var keyword is omitted and a value is just assigned to a variable then it will have 'global scope'.
For global scope just leave off the var
varData = "smith";
© 2018 Better Solutions Limited. All Rights Reserved. © 2018 Better Solutions Limited TopPrevNext