Lorenzo Lorenzo - 2 months ago 6
Javascript Question

What is the "===!" operator doing?

I'am playing with some JavaScript and found something strange.

This code alerts "false" but gives no syntax errors. Someone could explain why adding one or even many

!!!
after
===
is no resulting with any errors ?

var i = void 0;
var b = i ===! void 0 ? "true" : "false";
alert(b);//display false but no syntax errors..

Answer

Whitespace means nothing so it is

var b = (i === (!void 0))  ? "true" : "false";

which is

var b = (i === true) ? "true" : "false";

MDN Operator Precedence