JavaScript Basics Summary (Hoisting, Strict Mode)
Rules for Variable and Function Hoisting
- Variable hoisting: Execution still happens in order; variable declarations are hoisted but assignments are not.
- Function hoisting: The entire function body is hoisted to the top of its scope.
- Priority: Function hoisting > Variable hoisting.
1 | console.log(a); // undefined |
Using Strict Mode with use strict
What it does:
- Prevents creating accidental global variables;
- Disallows using undeclared variables, helping avoid memory leaks;
- Binds
thistoundefinedby default instead ofwindow.
1 | function foo() { |
1 | (function() { |