J

JavaScript Handbook

Clean • Professional

JavaScript Operators — Top Interview Questions & Answers

4 minute

JavaScript Operators — Interview Questions & Answers

Ques: What are Operators in JavaScript?

Ans: Operators are symbols used to perform operations on values and variables, such as addition, comparison, or logic.

Example:

let a = 10, b = 5;
console.log(a + b); // 15

Ques: What are the different types of operators in JavaScript?

Ans: JavaScript provides several types of operators:

TypeExampleDescription
Arithmetic+ - * / % **Perform math operations
Assignment= += -= *= /=Assign values
Comparison== === != !== > < >= <=Compare values
Logical`&& 
Bitwise`&^ ~ << >> >>>`
Ternary? :Conditional check
Typetypeof, instanceofCheck data types
String+, +=Concatenate strings

Ques: What are arithmetic operators?

Ans: These are used to perform mathematical calculations.

OperatorDescriptionExampleOutput
+Addition5 + 27
-Subtraction5 - 23
*Multiplication5 * 210
/Division10 / 25
%Modulus (Remainder)10 % 31
**Exponentiation2 ** 38

Example:

let x = 10;
x++;
console.log(x); // 11
x--;
console.log(x); // 10

Ques: What are assignment operators?

Ans: They are used to assign or update values to variables.

OperatorExampleEquivalent To
=x = 5x = 5
+=x += 3x = x + 3
-=x -= 2x = x - 2
*=x *= 2x = x * 2
/=x /= 2x = x / 2
%=x %= 2x = x % 2

Example:

let num = 10;
num += 5;
console.log(num); // 15

Ques: What are comparison operators used for?

Ans: Comparison operators are used to compare two values and return a boolean (true or false).

OperatorDescriptionExampleOutput
==Equal to5 == '5'true
===Strict equal to5 === '5'false
!=Not equal to5 != '5'false
!==Strict not equal to5 !== '5'true
>Greater than6 > 3true
<Less than2 < 5true
>=Greater than or equal5 >= 5true
<=Less than or equal4 <= 6true

Ques: What are logical operators?

Ans: Logical operators combine or invert conditions and return a boolean (true / false).

OperatorDescriptionExampleResult
&&Logical AND(5 > 2 && 6 > 3)true
` `Logical OR
!Logical NOT!(5 > 2)false

Example:

let age = 25;
if (age >= 18 && age <= 30) {
  console.log("Eligible");
}

Ques: What are bitwise operators?

Ans: These perform operations at the binary (bit) level.

OperatorDescriptionExampleResult
&AND5 & 11
``OR`5
^XOR5 ^ 14
~NOT~5-6
<<Left shift5 << 110
>>Right shift5 >> 12

Ques: What is the ternary operator?

Ans: The ternary operator is a shortcut for if...else statements.

Syntax:

condition ? value_if_true : value_if_false;

Example:

let age = 18;
let result = (age >= 18) ? "Adult" : "Minor";
console.log(result); // Adult

Ques: What are type operators?

Ans: Used to check data types or relationships of objects.

OperatorDescriptionExampleOutput
typeofChecks data typetypeof 42"number"
instanceofChecks instancearr instanceof Arraytrue

Example:

console.log(typeof "Hello"); // string
console.log(typeof null); // object
console.log([1, 2] instanceof Array); // true

Ques: What are string operators?

Ans: The + and += operators are used to concatenate strings.

Example:

let str1 = "Hello";
let str2 = "World";
console.log(str1 + " " + str2); // "Hello World"

Ques: What is operator precedence?

Ans: It defines the order in which operations are performed.

Example:

let result = 10 + 5 * 2;
console.log(result); // 20 (Multiplication before Addition)

Ques: What’s the difference between == and ===?

  • == → Compares values only (performs type conversion).
  • === → Compares value and data type (strict).

Example:

0 == false; // true
0 === false; // false

Ques: What will "5" + 2 and "5" - 2 return?

"5" + 2; // "52" (string concatenation)
"5" - 2; // 3 (string converted to number)

Ques: What is typeof null?

Ans: Returns "object" — this is a known JavaScript bug.

Ques: What is operator associativity?

Ans: It defines direction of execution

  • Left-to-right (+, , , /)
  • Right-to-left (=, *)

Article 0 of 0