JavaScript Operators

In Java Script there are different types of operators which can be used for various operations. Followings are the list of operators in Java Script.

  • Arithmetic Operators
  • Assignment Operators
  • Comparison Operators
  • String Operators
  • Logical Operators
  • Bitwise Operators
  • Ternary Operators
  • TypeOf Operators

JavaScript Arithmetic Operators

In Java Script ‘Arithmetic Operators’ are used to perform arithmetic operations on given numbers.

let a = 5;
let x = (100 + 50) * a;
document.getElementById("demo").innerHTML = x;

Following is the list of ‘Arithmetic Operators’:

Operator symbolDescription
+Used for Addition.
Used for Subtraction
%Mod – Division Remainder
**Exponentiation (support from ES2016 onwards)

JavaScript Assignment Operators

Assignment operators assign values ​​to JavaScript variables. The plus assignment operator (+=) adds a value to a variable. For example

let x = 6;
x += 5;

JavaScript Comparison Operators

In Java Script Comparison Operators is used to do comparison between two values. It always returns either true or false value. For example,

Operator SymbolDescription
==Equal to
===Equal value and equal data type
!=Not equal
!==Not equal value or not equal data type
>=Greater than or equal to
<=Less than or equal to
>Greater than
<Less than

JavaScript String Comparison

All above comparison operators can also be used with strings:

let text1 = "one";
let text2 = "two";
let result = text1 < text2;

JavaScript Logical Operators

Logical operators are used to determine the logic between variables or values. for example

  • && is logical AND
  • || is logical OR
  • ! is logical NOT

JavaScript Bitwise Operators

Bitwise operators operate on 32-bit numbers. Any digital operands in the operation are converted to a 32-bit number. The result is converted back to a JavaScript number.

  • & Bitwise AND operator
  • | Bitwise OR operator
  • ~ Bitwise NOT operator

JavaScript Ternary Operators

The “Question mark” (?) or “conditional” operator in JavaScript is known as ternary operator that has three operands. It is the simplified operator of if/else.

    let PassMarks = 40
    let result = (PassMarks > 39) ?  "PASS" : "FAIL";

You can also set multiple conditional operators as given in below example

         let marks = 95;
         let result = (marks < 40) ? "Unsatisfactory" :
        (marks < 60) ? "Average" :
           (marks < 80) ? "Good" : "Excellent";

TypeOf Operators

It returns the data type of the operand as a string. An operand can be any object, function, or variable. It returns the operand type. Types that can exist in Java Script are undefined, Object, boolean, number, string, symbol, and function.

typeof YourVariable;
    let a = 101; 
    let b = ""; 
    let c = null; 
    console.log("Type of a = " + (typeof a)); 
    console.log("Type of b = " + (typeof b));
    console.log("Type of c = " + (typeof c));


Type of a = number
Type of b = string
Type of c = object

Leave a Reply

Your email address will not be published. Required fields are marked *