DEV Community


Discussion on: 17 Pro JavaScript tricks you didn't know

dakujem profile image
Andrej Rypo • Edited
if(a!=123) // legible to anyone
if(a^123) // wtf
Enter fullscreen mode Exit fullscreen mode

I don't believe this code actually improves anything, like many other snippets presented here. It sacrifices one keyboard hit for legibility.

While I might be dumb for not knowing the trick, the difficulty is to make the code better understandable, not vice versa.

aralroca profile image
Aral Roca

And doesn't work as expected.... Boolean(123.1^123) // false, but should be true

hoggworks profile image
Brian Hogg

Yeah, the XOR operator isn't doing an equivalence check, at least not in the way the OP is presenting. It's just not a relevant tool to use, I don't think.