question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Rule to prevent assigning any value to a variable named undefined

See original GitHub issue

The 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:closed
  • Created 7 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
nzakascommented, Feb 7, 2017

This is pretty specific, so I’d suggest creating a custom rule instead.

0reactions
not-an-aardvarkcommented, Feb 25, 2017

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found