JavaScript defines four basic data types as follows:
- numbers
- may be any number, such as: 23, 5.7, or 34e6
- strings
- any alpha-numeric data, such as: "Hello, this is page 1"
- boolean
- used for results of decisions and may only be true or false, not any other value, such as 0 or -1
- null
- represented by the special keyword 'null' which represents nothing
These data types apply to both literals and variables. When using variables, the data type is determined by the interpreter, based on the contents of the variable.
For example, if the variable contains the value "Hello", the interpreter treats the variable as a string data type automatically. If the variable contained the value 10, the interpreter would treat the variable as a number.
When declaring variables in JavaScript, the following rules apply:
name or _ctrl_val are valid names, but
1stname and 1234 are not.