Closure is a function having access to the parent scope, even after the parent function has closed.
-
hoisting -
var
declarations, wherever they occur, are processed before any code is executed. -
scope - is its current execution context, which is either the enclosing function or, for variables declared outside any function, global. If you re-declare a JavaScript variable, it will not lose its value.
-
Declared variables are constrained in the execution context in which they are declared. Undeclared variables are always global.
-
Declared variables are created before any code is executed. Undeclared variables do not exist until the code assigning to them is executed.
-
Declared variables are a non-configurable property of their execution context (function or global). Undeclared variables are configurable (e.g. can be deleted).
- Scope - only within block
{...}
. - Cannot be redeclared in current block.
- When declaring a variable in a loop for (let ...) - it is visible only in this loop. And each iteration has its own let variable.
- Temporal dead zone - cannot be accessed before initialization. (otherwise
ReferenceError: Cannot access '<variable name>' before initialization
)
The same as let
except cannot be reassigned.
The prototype is the “backup storage of properties and methods” of an object that is automatically used during a search. Also it's a better place for object methods as they are shared between object instances.
__proto__ - field on object that points to its prototype