You are viewing a single thread.
View all comments View context
21 points

JS’s == has some gotchas and you almost never want to use it. So === is what == should have been.

All examples are true:

"1" == true
[1, 2] == "1,2" 
" " == false
null == undefined 

It isn’t that insane. But some invariants that you may expect don’t hold.

"" == 0
"0" == 0
"" != "0" 
permalink
report
parent
reply
5 points

One neat feature is you can compare to both null and undefined at the same time, without other falsey values giving false positives. Although that’s not necessary as often now that we have nullish coalescing and optional chaining.

permalink
report
parent
reply
2 points

I just tested and Terser will convert v === null || v === undefined to null==v. Personally I would prefer to read the code that explicitly shows that it is checking for both and let my minifier/optimizer worry about generating compact code.

permalink
report
parent
reply
0 points

Try changing to const === variable. That’s most likely what’s it doing to minimize the risk of accidental assignment.

permalink
report
parent
reply

Programmer Humor

!programmer_humor@programming.dev

Create post

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

  • Keep content in english
  • No advertisements
  • Posts must be related to programming or programmer topics

Community stats

  • 3.2K

    Monthly active users

  • 1K

    Posts

  • 38K

    Comments