So what do these nitty-gritty details boil down to? Step back and consider the entire flow of a JS source program:
1. After a program leaves a developer's editor, it gets transpiled by Babel, then packed by Webpack (and perhaps half a dozen other build processes), then it gets delivered in that very different form to a JS engine.
2. The JS engine parses the code to an AST.
3. Then the engine converts that AST to a kind-of byte code, a binary intermediate representation (IR), which is then refined/converted even further by the optimizing JIT compiler.
4. Finally, the JS VM executes the program.
1. After a program leaves a developer's editor, it gets transpiled by Babel, then packed by Webpack (and perhaps half a dozen other build processes), then it gets delivered in that very different form to a JS engine.
2. The JS engine parses the code to an AST.
3. Then the engine converts that AST to a kind-of byte code, a binary intermediate representation (IR), which is then refined/converted even further by the optimizing JIT compiler.
4. Finally, the JS VM executes the program.
эвристический — не являющийся гарантированно точным, но достаточный для решения задачи
what is closure
closure is when a function remembers and continues to access variables from outside its scope, even when the function is executed in a different scope.
closure is when a function remembers and continues to access variables from outside its scope, even when the function is executed in a different scope.
what is hoisting
when all variables declared anywhere in a scope are treated as if they're declared at the beginning of the scope
when all variables declared anywhere in a scope are treated as if they're declared at the beginning of the scope
шок-контент. каждый файл в ноде это модуль, а каждый модуль это функция
записать что-то в глобальную переменную можно только через`global`
записать что-то в глобальную переменную можно только через`global`
как называется глобальный объект в разных окружениях:
браузер —
браузер —
window
нода — global
веб-воркер — self
скоро это всё должно замениться на кроссокруженческий globalThisA function declaration is hoisted and initialized to its function value (again, called function hoisting). A var variable is also hoisted, and then auto-initialized to undefined
сначала всплывают function declaration, а потом переменные, объявленные через var
So to summarize, TDZ errors occur because let/const declarations do hoist their declarations to the top of their scopes, but unlike var, they defer the auto-initialization of their variables until the moment in the code's sequencing where the original declaration appeared. This window of time (hint: temporal), whatever its length, is the TDZ.