Variables

Variables can be declared with the 'var', 'let' or 'const' 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 semicolon 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;

Naming Conventions

Variable names can only contain letters, digits or the $ (dollar) or _ (underscore) characters
The first character cannot be a digit
camelCase is usually used.
Variable names are case sensitive.

let $ = 1; 
let _ = 2;
let digits123 = 3;


All On One Line

The semicolon 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();  



© 2019 Better Solutions Limited. All Rights Reserved. © 2019 Better Solutions Limited TopPrevNext