What happens when you declare var globally versus let or const?

WHAT IT TESTS: knowledge that var creates a Window property while let and const do not. A good answer notes var adds window.x, let/const do not pollute the global object, yet both are globally scoped. RED FLAG: claiming let/const lack global scope.
WHAT IT TESTS: understanding that global var declarations create properties on the browser's global Window object, while let and const declarations do not. A good answer explains that var x makes window.x, making it deletable and enumerable as a property, whereas let x and const x bind identifiers in the global lexical environment without adding them to window. It should mention globalThis as the environment-agnostic way to reference the global object.
Read the original → developer.mozilla.org
- #javascript
- #global-scope
- #browser
- #var
- #es6
Get five bites like this every day.
Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.