JavaScript Operators Explained | Arithmetic, Comparison, Logical & More with Examples

Himmat Kumar Jun 1, 2025, 6:37 AM
Blog Thumbnail

JavaScript Operators

JavaScript operators are used to perform operations on values and variables — such as arithmetic, assignment, comparison, and more. Let’s break them down with simple examples.

JavaScript Assignment

The assignment operator = assigns a value to a variable:

let x = 10;     // Assign 10 to x
let y = 2;      // Assign 2 to y
let z = x + y;  // Assign 12 to z

JavaScript Addition

let x = 5;
let y = 2;
let z = x + y;  // Result is 7

JavaScript Multiplication

let x = 5;
let y = 2;
let z = x * y;  // Result is 10

Types of JavaScript Operators

  • Arithmetic Operators
  • Assignment Operators
  • Comparison Operators
  • String Operators
  • Logical Operators
  • Bitwise Operators
  • Ternary Operator
  • Type Operators

JavaScript Arithmetic Operators

Used for basic math:

let a = 3;
let x = (100 + 50) * a;  // Result is 450
Operator Description
+Addition
-Subtraction
*Multiplication
/Division
%Modulus (Remainder)
**Exponentiation (Power)
++Increment
--Decrement

JavaScript Assignment Operators

let x = 10;
x += 5;  // Same as x = x + 5
Operator Example Same As
=x = yx = y
+=x += yx = x + y
-=x -= yx = x - y
*=x *= yx = x * y
/=x /= yx = x / y
%=x %= yx = x % y

JavaScript Comparison Operators

Return true or false based on comparison:

let age = 20;
console.log(age >= 18); // true

JavaScript Logical Operators

  • && AND: true if both are true
  • || OR: true if one is true
  • ! NOT: reverses boolean
let isLoggedIn = true;
let isAdmin = false;

console.log(isLoggedIn && isAdmin); // false

JavaScript String Operator

The + operator also joins (concatenates) strings:

let firstName = "John";
let lastName = "Doe";
let fullName = firstName + " " + lastName;

JavaScript Bitwise Operators

Operate on binary numbers (less common in day-to-day JS):

  • & AND
  • | OR
  • ^ XOR
  • ~ NOT
  • << Left Shift
  • >> Right Shift

JavaScript Ternary Operator

A shorthand for if...else:

let age = 16;
let result = (age >= 18) ? "Adult" : "Minor";

JavaScript Type Operators

typeof checks the type, instanceof checks object type:

typeof "Hello"      // "string"
typeof 123           // "number"
[] instanceof Array  // true

Related Posts

Himmat Kumar Jun 1, 2025, 1:11 AM

JavaScript Functions & Scope

Himmat Kumar Jun 1, 2025, 1:07 AM

Introduction JavaScript

Himmat Kumar Jun 1, 2025, 1:07 AM

JavaScript Variables: var vs let vs const

Himmat Kumar Jun 1, 2025, 1:07 AM

JavaScript Data Types Explained with Examples

Himmat Kumar Jun 1, 2025, 1:07 AM

JavaScript Loops — for, while, do...while

Himmat Kumar Jun 1, 2025, 1:07 AM

Date and Time in JavaScript — Easy Guide

112 viewsLaravel
Himmat Kumar Jun 1, 2025, 12:53 AM

Master Laravel: Basic System Requirement,Installation a...