Rule proposal: `no-typeof-undefined`
See original GitHub issueLess code written
Fail
typeof foo === 'undefined'
Pass
foo === undefined
Issue Analytics
- State:
- Created 2 years ago
- Reactions:6
- Comments:13 (6 by maintainers)
Top Results From Across the Web
undefined - JavaScript - MDN Web Docs - Mozilla
A function returns undefined if a value was not returned . ... One reason to use typeof is that it does not throw...
Read more >Documentation - TypeScript 3.7
only checks for whether the value on the left of it is null or undefined - not any of the subsequent properties. You...
Read more >"undefined" should not be passed as the value of optional ...
TypeScript static code analysis. Unique rules to find Bugs, Vulnerabilities, Security Hotspots, and Code Smells in your TYPESCRIPT code.
Read more >Why is undefined assignable to void? - Stack Overflow
In strict null checking mode, the null and undefined values are not in the domain of every type and are only assignable to...
Read more >Cannot Read Property of Undefined in JavaScript - Rollbar
In JavaScript, properties and functions can only belong to objects. Since undefined is not an object type, calling a function or a property...
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 don’t think
no-undef
is safe, for example, when you write code for browser, the following won’t report, becauseAbortController
is considered “defined” as globals.But when you run this code in old browsers don’t support
AbortController
, it will throw.This won’t.
Of cause,
'AbortController' in globalThis
orglobalThis.AbortController
are safer. But nothing wrong to usetypeof
.When it’s undefined variable,
foo === undefiend
will throw