It is a set of rules.
# declare variables
var a, b, c,
# assign values
a = 4 ; b = 6;
# c = 10
c = b + a;
You can type numbers with decimals or without.
You can type strings with double or single quotes.
There are two types of values:
variable values and Fixed values
Variable values are called variables.
Fixed values are called literals.
( 40 - 10 ) * 2
var y, x,
y = 4 ;
x = 2 ;
When we combine variables, values, and operators, it is called evaluation
For example, 2 * 5 evaluates to 10:
Expressions can also contain variable values:
tip: You can also use numbers or strings, so "Bruce" + "Clynt" evaluates "Bruce Clynt"
Variable is used to store data value.
Use the var keyword to declare variable.
You can also use = sign to assign values to variables.
Next example shows how Z is defined as var (variable), then we give Z which is now variable the value of 10
z = 10;
Any of these three /* // */ signs are used to write comment that the computer will not execute and ignore.
var z =
10 ; // This will be executed
// var x = 11; this will NOT be executed
Keywords order the browser to create variables, the var
in the example below is keyword:
var z, x;
x = 2 + 3 ;
z = x * 2 ;
Identifier is used to name variables, keywords, labels, and functions.
The first character must be a letter, or an underscore or a dollar sign
tip: You can't type numbers as first character of identifier.
tip: Identifiers are case sensitive, David and david, are not the same variables.