Begin Web Programming with PHP & MySQL

Advertisements



JavaScript Operators

An operator is a symbol or sign used to specify an operation to be performed in a programming language.
Consider the mathematical operation 6 + 4 = 10
Here 6 and 5 are called operands and ‘+’ is called the operator.
JavaScript supports the following types of operators.

  • Arithmetic Operators
  • Assignment Operators
  • Comparison Operators
  • Conditional Operators
  • Logical Operators

JavaScript Arithmetic Operators

Arithmetic operators are used to perform arithmetic on numbers:
Operator Description
+ Addition
- Subtraction
* Multiplication
/ Division
% Modulus (Division Remainder)
++ Increment
-- Decrement

In Javascript "+" sign is used for the string operation "concatenation" also.

JavaScript Assignment Operators

Assignment operators assign values to JavaScript variables.
Operator Example Meaning
=a = ba = b
+=a += ba = a + b
-=a -= ba = a - b
*=a *= ba = a * b
/=a /= ba = a / b
%=a %= ba = a % b

In Javascript "+" sign is used for the string operation "concatenation" also.

JavaScript Comparison Operators

Operator Description
== equal to
=== equal value and equal type
!= not equal
!== not equal value or not equal type
> greater than
< less than
>= greater than or equal to
<= less than or equal to
? ernary operator

JavaScript Logical Operators

Operator Description
&& logical 'and'
|| logical 'or'
! logical not

JavaScript Type Operators

Operator Description
typeof Returns the type of a variable
instanceof Returns true if an object is an instance of an object type

JavaScript Bitwise Operators

Bit operators work on 32 bits numbers. Any numeric operand in the operation is converted into a 32 bit number. The result is converted back to a JavaScript number.

Operator Description Eg: Meaning Result Decimal
& AND5 & 10101 & 00010001 1
| OR 5 | 1 0101 | 0001 0101 5
~ NOT ~ 5 ~0101 1010 10
^ XOR 5 ^ 1 0101 ^ 0001 0100 4
<< left shift5 << 1 0101 << 1 101010
>> right shift 5 >> 1 0101 >> 1 0010 2
>>> unsigned right shift 5 >>> 1 0101 >>> 100102