-
Notifications
You must be signed in to change notification settings - Fork 4
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
Explicit check for undefined #36
Comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In some places the check for undefined values is done implicitly as follows:
This can lead to errors, if the value is not undefined, but an empty string, an empty array, a number with value 0, a false Boolean, ...
The not operator
!
returns true for such values and the guarding if triggers when it should not. The only place where the ! operator can be used for such a check is, when the behavior should be same for these falsy values and an undefined value. We should maybe consider to even use explicit checks in such cases to make the intention of the code more clear, even though this leads to more verbose code.Check for only undefined before:
Check for only undefined better:
Check for undefined and falsy before:
Check for undefined and falsy more explicit:
TODO:
The text was updated successfully, but these errors were encountered: