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

typeof variable === "object" potentially problematic #249

Open
mjsarfatti opened this issue May 27, 2020 · 1 comment
Open

typeof variable === "object" potentially problematic #249

mjsarfatti opened this issue May 27, 2020 · 1 comment

Comments

@mjsarfatti
Copy link

On the type checking section the following is recommended to see if a variable is an object:

typeof variable === "object"

The problem is that:

typeof null === "object"

So the recommendation should probably read:

typeof variable === "object" && variable !== null
@ferdnyc
Copy link

ferdnyc commented Jan 2, 2024

Though, some coders will prefer to shorten that to,

typeof variable === "object" && variable

(That works because, if variable is an object, only null will test false.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants