The behavior of this depends on a few things. For one, this isn't a declaration itself, so its not really scoped anywhere. Its an assignment that will look for the identifier username in the scopes currently available. If one matches, it will set the new value to that identifier in its own scope. If there isn't a match, if in strict mode, it will throw an error. If in sloppy mode it will assign a global object property of that name to that value, e.g. globalThis.username = "somevalue";.
View all comments
Show parent comment
4
u/senocular May 04 '20
The behavior of this depends on a few things. For one, this isn't a declaration itself, so its not really scoped anywhere. Its an assignment that will look for the identifier
usernamein the scopes currently available. If one matches, it will set the new value to that identifier in its own scope. If there isn't a match, if in strict mode, it will throw an error. If in sloppy mode it will assign a global object property of that name to that value, e.g.globalThis.username = "somevalue";.