3 ms·
Are all variables still global unless defined not to be?
by soperj 3y ago
Are all variables still global unless defined not to be?
- bunga-bunga 3y agoNot in a module context: # a.mjs (()=>{ a = 1 })(); # in a shell $ node a.mjs ReferenceError: a is not defined
- post-it 3y agoNo, as of eight years ago. https://en.wikipedia.org/wiki/ECMAScript_version_history#ES2015 https://en.wikipedia.org/wiki/ECMAScript_version_history#ES2...
- soperj 3y agothanks!
- bmacho 3y agoI'd rather say yes. AFAIK core javascript works exactly like 25 years ago, and they haven't changed anything on it, not removing a single keyword or altering a semantics of any less used function, so your 25 years old javascript programs can still run in modern browsers.
- Mystery-Machine 3y agoThe short answer is: yes. If you do <script scr=...> And in the .js file: var x = 5. That x is global.