Make vars-on-top work with let and const
See original GitHub issueRight now this gives no warning:
function foo(bar) {
if(bar) {
doSomething();
}
const baz = "bar";
return baz;
}
foo();
given this config:
{
"rules": {
"strict": 0,
"vars-on-top": 2
},
"ecmaFeatures": {"blockBindings": true},
"globals": {
"doSomething": false
}
}
(Note, it does warn if I include a regular var
in there):
function foo(bar) {
if(bar) {
doSomething();
}
const baz = "bar";
var foobar = "eggs";
return {baz: baz, foobar: foobar};
}
foo();
I would expect that it should warn in the first case.
Issue Analytics
- State:
- Created 8 years ago
- Comments:22 (20 by maintainers)
Top Results From Across the Web
Var, Let, and Const – What's the Difference? - freeCodeCamp
Scope essentially means where these variables are available for use. var declarations are globally scoped or function/locally scoped. The scope ...
Read more >let, var, and const - Go Make Things
ES6 introduced two new ways to define variables: let and const. ... This works because it's a different scope let chips = 'Wise'; ......
Read more >ES6 In Depth: let and const - the Web developer blog
I like to imagine the JS engine lifting each var and function to the top of the enclosing function with a tiny code...
Read more >Hoisting in Modern JavaScript — let, const, and var
Many JavaScript programmers explain hoisting as JavaScript's behavior of moving declarations (variable and function) to the top of their ...
Read more >Are variables declared with let or const hoisted?
Is there any difference between let and const in this matter? ... 1: var declarations are still working only on the function level, ......
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
Was a plugin for this ever made? I agree that it should be block scoped, and fine with it being off by default, but it’d be nice to be able to enforce this from a stylistic aspect.
Though, perhaps I should leave this open to add an option for stylistic reasons. Anyone think that would be handy? I’d definitely use it.