Rule to prevent assigning any value to a variable named undefined
See original GitHub issueThe docs for the no-undefined
rule gives this example. I don’t want to use the no-undefined
rule, since I use undefined in many places. But it would be useful to have a rule that doesn’t allow the shadowing of undefined to happen, where you can’t assign a value to a variable named undefined
in any way. (Like var, let, const, destructuring, function arguments, etc)
function doSomething(data) {
var undefined = "hi";
// doesn't do what you think it does
if (data === undefined) {
// ...
}
}
Issue Analytics
- State:
- Created 7 years ago
- Comments:6 (5 by maintainers)
Top Results From Across the Web
Can I set variables to undefined or pass ... - Stack Overflow
When you declare a variable by having a var a statement in a block, but haven't yet assigned a value to it, it...
Read more >Disallow Use of undefined Variable (no-undefined) - ESLint
As an alternative, you can use the no-global-assign and no-shadow-restricted-names rules to prevent undefined from being shadowed or assigned a different value.
Read more >1.6 — Uninitialized variables and undefined behavior
Uninitialized means the object has not been given a known value (through any means, including assignment). Therefore, an object that is not ...
Read more >Rule proposal: no-null · Issue #6701 · eslint/eslint - GitHub
The language itself uses undefined for any uninitialized variable and it's also the default return value of functions. Therefore one can argue ...
Read more >How the let, const, and var Keywords Work in JavaScript
With var in non-strict mode, the variable will have an undefined value. This means that a variable has been declared but has no...
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
This is pretty specific, so I’d suggest creating a custom rule instead.
It looks like there is consensus that this would be a better fit for a custom rule, so I’m going to close this issue. Thanks anyway for the suggestion – if you do end up implementing a custom rule for this, feel free to link it here.