Variables and OperatorsIn this tutorial you will learn the basics of programming, which are required to write a script. These notions are similar to those of PHP and other programming languages.
1. Using variables
In a script (or program) we use constants and variables datas. The variables can change their values during program execution. These data are called "variables".
- Variable = name of a location in computer memory, used to store data.
You can create a variable and assign a value to it in this way:
- With statement var
var x = "xyz"; x = 8;- Notice that the 'string' values (consisting of letters) are written between quotation marks (simples or doubles), and the 'number' can be written without quotation marks.
The variables created out of the functions can be used everywhere in that script, inclusively inside the functions and other JS script from that HTML page.
To work with datas in a script and manipulate variable values we use operators.
Operators are symbols and identifiers that determines how data are modified and how it is evaluated a combination of expressions and variables.
- - binary operators - that need two operands.
- - unary operators - that need only one operand.
- Arithmetic operators
- Assigning operators
- Comparation operators
- Logical operators (booleans)
- Operators for strings
- Typeof operator
- Conditional operator (? :)
- Operators for functions
- Operators for objects