Fundamentals of the JavaScript syntax

Here is a quick reference to many of the basic handles and definitions for the JavaScript language.

Comparision and conditional operators
Name Operator Description
Equal  == Returns true if the operands are equal
Strict equal  === Returns true if the operands are equal and of the same type
Not equal  != Returns true if the operands are not equal
Strict not equal !== Returns true if the operands are not equal or not of the same type
Greater than  > Returns true if the left operand is greater than the right operand
Les than < Returns true if the left operand is less than the right operand
Greater than or equal >= Returns true if the left operand is greater than or qual to the right operand
Less than or equal <= Returns true if the left operand is less than tor euqal to the right operand

 

Assignment Operators
Assignment  = Assigns the value of the right operand to the left operand
Compound addition assignment  += Combines the value of the right operand with the value of the left operand or adds the value of the right operand to the value of the left operand and assigns the new value to the left operand
Compound subtraction assignment  -= Subtracts the value of the right operand from the value of the left operand and assigns the new value to the left operand
Compound multiplication assignment  *= Multiplies the value of the right operand by the value of the left operand and assigns the new value to the left operand
Compound division assignment  /= Divides the value of the left operand by the value of the right operand and assigns the new value to the left operand
Compound modulus assignment  %= Divides the value of the left operand by the value of the right operand and assigns the remainder (the modulus) to the left operand

 

Data Types
Number Positive or negative numbers with or without decimal places, or number written using exponential notation
Boolean A logical value of true or false
String Text such as "Hello World"
Undefined A variable that has never had a value assigned to it, has not been declared, or does not exist
Null An empty value

 

Building Expressions
Operator type Operators Description
Arithmetic addition(+), subtraction(-), multiplication(*), division(/), modulus(%), increment(++), decrement(--), negation(-) Used for performing mathematical calculations
Assignment assignment (=), compound addition assignment (+=), compound subtraction assignment (-=), compound multiplication  assignment (*=), compound division assignment (/=), compound modulus assignment (%=) Assigns values to variables
Comparison equal (==), strict equal (===), not equal (!=), strict not equal (!==), greater than (>), less than (<), greater than or equal to (>=), less than or equal to (<=) Compares orperands and returns a Boolean value
Logical and (&&), or (||), not (!) Used for performing Boolean operations on Boolean operands
String concatenation operator (+), compound assignment operator (+=) Performs operation on astrings
Special property access (.), array index ([]), function call (()), comma (,), conditional expression (?:), delete (delete), property exists (in), object type (instancedof), new object (new), data type (typeof), void (void) Used for various purposes and do not fit within other operator categories

 

Arithmetic Binary Operators
Addition + Adds two operands
Subtraction - Subtracts one operand from another operand
Multiplication * Multiplies one operand by another operand
Division / Divides one operand by another operand
Modulus % Divides one operand by another operand and returns the remainder

 

Arithmetic Unary Operators
Increment  ++ Increases an operand by a value of one
Decrement  -- Decreases an operand by a value of one
Negation  - Returns the oposite value (negative or opsitive) of an operand

 

Assignment Operators
Assignment  = Assigns the value of the right operand to the left operand
Compound addition assignment  += Combines the value of the right operand with the value of the left operand or adds the value of the right operand to the value of the left operand and assigns the new value to the left operand
Compound subtraction assignment  -= Subtracts the value of the right operand from the value of the left operand and assigns the new value to the left operand
Compound multiplication assignment  *= Multiplies the value of the right operand by the value of the left operand and assigns the new value to the left operand
Compound division assignment  /= Divides the value of the left operand by the value of the right operand and assigns the new value to the left operand
Compound modulus assignment  %= Divides the value of the left operand by the value of the right operand and assigns the remainder (the modulus) to the left operand

 

Comparision and conditional operators
Name Operator Description
Equal  == Returns true if the operands are equal
Strict equal  === Returns true if the operands are equal and of the same type
Not equal  != Returns true if the operands are not equal
Strict not equal !== Returns true if the operands are not equal or not of the same type
Greater than  > Returns true if the left operand is greater than the right operand
Les than < Returns true if the left operand is less than the right operand
Greater than or equal >= Returns true if the left operand is greater than or qual to the right operand
Less than or equal <= Returns true if the left operand is less than tor euqal to the right operand

 

Logical Operators
Name Operator Description
And  && Returns true if both the left operand and right operand return a vlue of true; otherwise, it returns a value of false
Or  || Returns true if either the left operand or right opernad returns a value of true; if neither operand returns a value of true, then the expression containing the or || operator returns a value of false
Not ! Returns true if an expression is false and returns false if an expression is true

 

Escape sequence
Escape sequence Character
 \\ Backslash
\b Backspace
\r Carriage return
\" Double quotation mark
\f Form feed
\t Horizontal tab
\n New line
\o Null character
\' Single quotation mark
\v Vertical tab
\XXX Latin-1 character specified by the XX characters, which represent two hexadecimal digits
\XXXXX Unicode character specified by the XXXX characters, which represent four dexadecimal digits

 

Special Operators
Name Operator Description
Property access . Appends an object, method, or property to another object
Array index [] Accesses an element of an array
Function call () Calls up functions or changes the order in which individual operations in an expression are evaluated
Comma , Allows you to include multiple expressions in the same statement
Conditional expression ?: Executes one of two expressions based on the results of a conditional expression
Delete delete Deletes array elements, variables created without the var keyword, and properties of custom objects
Property exists in Returns a value of true if a specified property is contained within an object
Object type instanceof Returns true if an object is of a specified object type
New object new Creates a new instance of a user-defined object type or a predefined JavaScript object type
Data type typeof Determines the data type of a variable
Void void Evaluates an expressions without returning a result

 

Values returned by typeof operator
Return value Returned for
Number Integers and floating-point numbers
String Text strings
Boolean True or false
Object Objects, arrays, and null variables
Function Functions
Undefined Undefined variables

 

Understanding Operator Precedence
Operators Description Associativity
. Objects-highest precedence Left to right
[] Array elements-highest precedence Left to right
() Functions/evaluation-highest precedence Left to right
* / % Multiplication/Division/Modulus Left to right
 + - Addition/subtraction/concatenation Left to right
< <= > >= Comparison Left to right
instanceof Object type Left to right
instanceof Object property Left to right
 == != === !== Equality Left to right
&& Logical and Left to right
 || Logical or Left to right
, Comma-lowest precedence Left to right
new New object-highest precedence Right to left
! Not Right to left
- Unary negation Right to left
 ++ Increment Right to left
 -- Decrement Right to left
typeof Data type Right to left
void void Right to left
delete Delete object Right to left
?: Conditional Right to left
 = += -= *= /= %= Compound assignment Right to left