What is === operator ?

=== is strict equality operator ,it returns true only when the two operands are having the same value without any type conversion.

In JavaScript, the === operator is called the “strict equality operator.” It compares two values, checking both their value and their data type to determine if they are equal.

Here’s how it works:

  1. If the types of the two values being compared are different, === returns false without any type conversion.
  2. If both values are of the same type, === behaves exactly like the == (equality) operator, comparing the values.
  3. However, unlike ==, === does not perform type coercion. This means that if the values being compared are of different types, they are considered unequal, even if they could be converted to the same value.

For example:

javascript
1 === 1 // true
1 === '1' // false
1 === true // false
0 === false // false

In contrast, the == operator would attempt to convert the operands to the same type before making the comparison. For example:

javascript
1 == '1' // true, because '1' is converted to a number
1 == true // true, because true is converted to 1
0 == false // true, because false is converted to 0

In most cases, it’s recommended to use the === operator because it provides more predictable behavior and helps prevent subtle bugs that can arise from type coercion.