When you use var in the console, it runs in the global scope and adds a variable to the window object.
When you use let in the console, it runs in a global scope that does not add a variable to the window object.
When you start typing, autocomplete checks the parent object for properties to complete, along with other language constructs such as function , for and while .
If there is no content in the console, the parent window object that will not have the property you are looking for because let does not add the property to window .
As soon as you have a new object to complete autocomplete, the behavior will return to what you expect.
> let foo = {bar: 'baz'}; > foo.b
Now, with all that has been said, there is no reason why autocomplete should behave this way. In many ways, the lack of autocomplete for variables globally defined with let can be considered a βmistakeβ worth a βcommitβ. In my opinion, this is a moderately surprising behavior.
source share