var variable_name = “value”;
var address = “new town”;
(We need to keep the name unique for this variable)
Variable value for string = “value will be within double or single quotation.”
Variable value for number or integer = value will be without double or single quotation.
Note: If variable is declared with the same name in a script and when it is call, the value will be immediate above variable.
- Global variable – a global variable has global facilities that means global variables defined in the entire script.
- Local variable – a local variable only useable in the functions where is defined.
Here an example of local and global variables:
There are some example/ rule of variable naming and declaring process:
Var name _one; // we declare a variable but do not assign any value, so the variable value is undefined;
Var name _two = 12.24; // this variable contains primitive data type with number value;
Var name _three = “test”; // this variable contains primitive data type with string value;
Var name _four = “123 test”; // this variable contains primitive data type with mix of number and string value;
Var name _five = 123 + “test”; // this variable contains primitive data type with numeric and string, creating a string variable;
Var name _six = (1>2); // this variable is a Boolean value;
Var name_seven = name _six; // this variable is assign with another variable;