Why === and not =

Hello everyone

I was was just wondering why we use === equaliser instead of just =. When I was younger and programming my ZX Spectrum we used = to check if something was equal to something.


It’s because in Javascript = is used as an assignment. (Oh and also, = is an operation.)

var x = 0;
x = 42;

Also remember:

x = 32;

The code at right above of this text returns undefined.

=== returns a boolean true/false according into is the left and right the same.

42 === 42 (returns true)
3 === β€˜3’ (returns false)
var x = 55 (returns undefined)
x === 45 (returns false)

Sorry for the loooooong explanation.

1 Like