JavaScript

JS Basics

JS Variables & Operators

JS Data Types & Conversion

JS Numbers & Math

JS Strings

JS Dates

JS Arrays

JS Control Flow

JS Loops & Iteration

JS Functions

JS Objects

JS Classes & Modules

JS Async Programming

JS Advanced

JS HTML DOM

JS BOM (Browser Object Model)

JS Web APIs

JS AJAX

JS JSON

JS Graphics & Charts

JavaScript

JS Basics

JS Variables & Operators

JS Data Types & Conversion

JS Numbers & Math

JS Strings

JS Dates

JS Arrays

JS Control Flow

JS Loops & Iteration

JS Functions

JS Objects

JS Classes & Modules

JS Async Programming

JS Advanced

JS HTML DOM

JS BOM (Browser Object Model)

JS Web APIs

JS AJAX

JS JSON

JS Graphics & Charts

JS Operators


📘 JavaScript Operators – Performing Operations in JS

Operators are used to perform operations on variables and values. JavaScript includes many types of operators for different tasks like math, logic, assignment, and comparison.


🔹 1. Arithmetic Operators

Used to perform mathematical operations:

Operator Description Example
+ Addition x + y
- Subtraction x - y
* Multiplication x * y
/ Division x / y
% Modulus (remainder) x % y
** Exponentiation x ** y
++ Increment x++ or ++x
-- Decrement x-- or --x

🔹 2. Assignment Operators

Used to assign values to variables:

Operator Example Same As
= x = y x = y
+= x += y x = x + y
-= x -= y x = x - y
*= x *= y x = x * y
/= x /= y x = x / y
%= x %= y x = x % y

🔹 3. Comparison Operators

Used to compare values and return true or false:

Operator Description Example
== Equal to x == y
=== Equal value and type x === y
!= Not equal x != y
!== Not equal value or type x !== y
> Greater than x > y
< Less than x < y
>= Greater than or equal to x >= y
<= Less than or equal to x <= y

🔹 4. Logical Operators

Used to combine conditions:

Operator Description
&& Logical AND (both true)
`  
! Logical NOT (inverse)

🔹 5. Type Operators
Operator Description
typeof Returns the type
instanceof Checks if an object is an instance of a class

🔹 6. String Concatenation

The + operator can also join strings:

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

Practice Questions

Q1. How do you add two numbers a = 5 and b = 10 and store the result in sum using an arithmetic operator?

Q2. How do you increment a variable x by 1 using the ++ operator?

Q3. How do you use the += assignment operator to add 20 to a variable points?

Q4. How do you compare two variables x = 5 and y = "5" using the == operator and the === operator?

Q5. How do you check if a number age is greater than or equal to 18 using a comparison operator?

Q6. How do you write a condition using logical AND (&&) to check if age is greater than 18 and citizen is true?

Q7. How do you use the modulus operator to check if a number x is even?

Q8. How do you use the typeof operator to find the type of a variable name?

Q9. How do you concatenate two strings "Hello" and "World" using the + operator and store in message?

Q10. How do you use instanceof to check if a variable person is an instance of a class Person?


JS Operators Quiz

Q1: Which operator is used for exponentiation in JavaScript?

A. ^
B. **
C. exp
D. ^^

Q2: What will 5 == "5" return?

A. true
B. false
C. undefined
D. NaN

Q3: Which operator checks both value and data type?

A. ==
B. !=
C. ===
D. =>

Q4: What is the result of "5" + 3 in JavaScript?

A. 8
B. 53
C. error
D. undefined

Q5: Which of the following is a logical OR operator?

A. &&
B. ||
C. ==
D. !=

Q6: What will the expression typeof 42 return?

A. "integer"
B. "number"
C. number
D. 42

Q7: Which operator is used to assign a value to a variable?

A. ==
B. =
C. !=
D. ===

Q8: Which operator is used to compare value only (not type)?

A. ==
B. ===
C. !=
D. !==

Q9: What does the ! operator do in JavaScript?

A. Adds 1
B. Negates a boolean value
C. Compares values
D. Declares a constant

Q10: What will true && false evaluate to?

A. true
B. false
C. undefined
D. error

Go Back Top