y = 5
x = 10
d = y + x
x = 1
z = 2
y = 10
y = x + z
#comment y equal to 3 and not 10 + 2 + 1, because we assigned x and z to y
y equal to 3 and not 10 + 2 + 1, because we assigned x and z to y
tip: Unlike assignment sign (=), "equal" sign (==) act diffrently.
x = 99
z = 100
x == z
We declared the variable x to 99, and z to 100, but at the end of the example x will be 100, beacuse we used the Equality Operator, don't forget.
Variables can hold numbers or text values.
For string we will use 'Mark' (single quotes), for numbers 10 (no quotes).
x = 10;
z = 'Mark';
y = "Jake";
Identifiers (variable name) can be letters, numbers, underscrores, or dollar sign.
Variables are case sensitive (x and X are not the same)
Variable must begin with a letter (unless it is number)
x = 'Jake' #good
z = '2jake' #error
r = 50 #good
y = 'code'
d = 'Code' # y and d are not the same variable!
var y = 10 + 10 + 10;
You can also use strings:
var z = "Jake" + " " + "Mark";
Once you declared Jake, you need to add value to it
Next step is to assign a value to Jake
Jake = "Boy";
More efficient way is to assign value and declare variable at the same time!
var jake = "Boy";
Even more efficient method is to declare and assign many variables at once.
var jake = "boy", color = "red", number = 10;
tip: In certain situations developer will declare variable with no value, for example if the value has to be calculated.