To declare a variable you use the
var keyword which tells the browser that the text to follow is the name of a new variable. A semicolon must end the statement!
var motorbikeprice = 3420;
The statement begins with the
var keyword (which tells the browser that what follows is the name of the variable), followed by the name of the variable, the assignment operator (=) (which tells the browser to assign the value from the right of the operator to the variable from the left of the operator), and the value of the variable. The statement ends with a semicolon.
is equal to. The operator
is equal to is two equal signs
When naming your variables you need to consider four things:
- Case sensitivity –
MoToRbIkEpRiCeare four different variables.
- Invalid characters – Name of a variable must begin with a letter or an underscore. Empty spaces are not allowed in variable names.
- Meaningful and easy to remember names.
abstract, as boolean, break, byte, case, catch, char, class, const, continue, debugger, default, delete, do, double, else, enum, export, extend, false, final, finally, float, for, function, goto, if, implements, import, in, instanceof, int,interface, is, long, namespace, native, new, null, package, private, protected, public, return, short, static, super, switch, synchronized, this, throw, throws, transient, true, try, typeof, use, var, void, volatile, while, with.