JavaScript Tutorial #05 Operators

Posted at: May 9, 2019 3:49 PM

In this lesson we will learn about operators in JavaScript.

An operator is a special type of symbols that performing specific types of operations. Like as 5 + 6 * 10 = 65 here is + and * is operators and 5, 6 and 10 is operands.

In JavaScript supports following types of operators.

  • Arithmetic Operators
  • Assignment Operators
  • Comparison Operators
  • Logical Operators
  • Bitwise Operators
  • String Operators
  • Conditional (ternary) Operators

Arithmetic Operators

JavaScript support following arithmetic operators

OperatorsName
+addition
-subtraction
*multiplication
/division
%modulo (returns the remainder)
++increment (can be prefix or postfix)
--decrement (can be prefix or postfix)

Example

Assignment Operators

Assignment operator is used to assign a value to a variable.

OperatorsName
=assign
+=add and assign
-+subtract and assign
*=multiply and assign
/=divide and assign
%=modulo and assign

Example

Comparison Operators

A comparison operators compare the operands with comparison operators and return logical value based on comparison is true.

OperatorsName
==equal
!=not equal
>greater than
>=greater than or equal to
<less than
<=less than or equal to
===identical (equal and of same type)
!==not identical

Example

Logical Operators

Logical operators used with boolean values. More than one relation can be logically joined using logical operators.

OperatorsName
&&Logical AND
||Logical OR
!Logical NOT

Example

Bitwise Operators

JavaScript support following binary bitwise operators.

OperatorsName
&AND
|OR
^XOR
~NOT
<<shift left (zero fill at right)
>>shift right

In Bitwise opertators converts operands in 32 bits numbers and work with bit by bit. For example the number of 5 and 6 have the binary represatation of 0101 and 0110.

Example

String Operators

Using string opertators concatenate the string.

OperatorsName
+concatenation
+=concatenate and assign

Example

Conditional (ternary) Operators

The conditional operator creates an expression that evaluates as one of two expressions depending on a condition.

conditions ? value1 : value2

Example

You can watch video on JavaScript Tutorial #05 Operators


javascript ternary operator javascript logical operators assignment operators conditional operators Bitwise Operators Comparison Operators Arithmetic Operators String Operators

Please leave comments

0 Comments

truecodex launched free android app. You can download and install truecodex app on your mobile and get notification of the latest post.

Video Tutorials on YouTube