require explicit check for undefined?
See original GitHub issueThis code has a runtime error. It will not use the 0
value.
Should Hegel force us to explicitly check undefined to avoid the runtime error?
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:11 (4 by maintainers)
Top Results From Across the Web
explicit typeof == "undefined" check vs just checking for its ...
The first explicitly checks that x.foo is undefined , whereas if (x.foo) is checking to see if x.foo is truthy.
Read more >Checking for undefined: === versus typeof versus falsiness
There are several ways of checking whether a variable has the value undefined. This blog post explains the differences.
Read more >How to check for undefined in JavaScript
Generally, comparing directly to undefined is still safe. There's no practical reason for an application to re-assign the value of undefined .
Read more >Null vs. Undefined - TypeScript Deep Dive - Gitbook
Checking for either. Fact is you will need to deal with both. Interestingly in JavaScript with == , null and undefined are only...
Read more >Documentation - TypeScript 2.0
In strict null checking mode the compiler requires every reference to a local variable of a type that doesn't include undefined to be...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I think it would make sense to warn on
Nullish | PossblyFalsy
used inif
,while
, ternary, etc. (whereNullish
is either null or undefined or union of both, andPossiblyFalsy
is any combination ofstring
,number
,bigint
andboolean
)This is what Flow does (with
sketchy-null
lint enabled), and there’sstrict-boolean-expressions
for typescript-eslint which also does that.I don’t think a linter could do a good job checking these things, otherwise the linter would become something like Hegel already is.