JavaScript syntax borrows heavily from C
and other C-like languages such as Java and Perl.
In JavaScript, everything is case-sensitive
variables, function names, and operators are case-sensitive
An identifier is the name of a variable, function, property, or argument
- may be one or more characters
- starts with a letter or
_
or$
- can contains letters, numbers,
_
,$
var Name; // OK
var name; // OK
var _; // OK
var _name1; // OK
var $; // OK
var $name2; // OK
var π; // OK
var Åmstrong; // OK
var 1name; // SyntaxError: Unexpected token ILLEGAL
Letters can be in extended ASCII or Unicode
//single line comment
/*
* This is a multi-line
* Comment
*/
For readability each line of block comment starts with *
Statements are terminated by a semicolon ;
var diff = a - b; //OK
var sum = a + b //OK but don't forget semicolon!
Statements can be combined into a code block between curly braces {
and }
{
test = false;
alert("hello!");
}
break case catch continue do
debugger default delete else finally
for function instanceof if in
new return switch this throws
try typeof var void while
with
abstract boolean byte char class
const debugger double enum export
extends final float goto implements
import int interface long native
package private protected public short
static super synchronized throws transient
volatile