var x = 5; var y = 6; var z = x + y;
Constant values such as 3.14 or “Tom Clancy” are called literals. Rules for writing these values are different for different types of data:
Numbers literals can be written with or without decimals
Text values are called Strings and written within double(“) quotes or single(‘) quotes:
"Tom Clancey"; 'Bill Gates the role model';
var keyword is optionally followed by equal (=) sign to assign values to variables.
In below example, variable x is defined with initial value of 5 whereas var y is defined without any initial value.
var x = 5; var y = x + 20; var z = (10 + 90)/y;
Variables can be part of Expressions
var KH_Count = 0; // correct var function; // wrong since function is a keyword and can't be used as a variable name
break case catch class const continue debugger default delete do else export extends finally for function if import in instanceof new of return super switch this throw try typeof var void while with yield