Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: x == null rule #279

Closed
rstacruz opened this issue Oct 2, 2015 · 7 comments

Comments

@rstacruz
Copy link
Member

commented Oct 2, 2015

The readme says:

Always use === instead of == – but obj == null is allowed to check null || undefined.

Why is == being permitted in this exception?

@dcousens

This comment has been minimized.

Copy link
Member

commented Oct 2, 2015

Probably because it broke a lot a lot of peoples code/assumptions otherwise.

@rstacruz

This comment has been minimized.

Copy link
Member Author

commented Oct 2, 2015

in that case, perhaps it should be considered for deprecation?

@dcousens

This comment has been minimized.

Copy link
Member

commented Oct 2, 2015

Possibly, there might be more to it. @feross?

@feross

This comment has been minimized.

Copy link
Member

commented Oct 12, 2015

It's a very common idiom in JS to check for null and undefined in one shot by using == null.

x == null is far nicer than x === null || x === undefined to the trained eye.

@dcousens

This comment has been minimized.

Copy link
Member

commented Oct 12, 2015

IMHO, if they can afford to be that loose with their arguments, I'd prefer just if (!x) {.
If they need to be specific enough such that == null is an option, IMHO they should be doing === null || === undefined.
But, that is just my opinion.

@feross

This comment has been minimized.

Copy link
Member

commented Oct 12, 2015

!x catches a bunch of other things like the empty string and the number 0. The == null idiom is common in node.js core and on npm.

@dcousens Maybe you're right, but this ship has sailed and it's not worth a breaking change.

@feross feross closed this Oct 12, 2015

@dcousens

This comment has been minimized.

Copy link
Member

commented Oct 12, 2015

@feross not even in a 6.0.0 if/when that happens?

@lock lock bot locked as resolved and limited conversation to collaborators May 10, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
3 participants
You can’t perform that action at this time.