- Synchronous code runs line-by-line.
- Asynchronous code allows work to continue while waiting (timers, IO, network).
console.log("A");
setTimeout(() => console.log("C"), 0);
console.log("B");
// Output: A, B, CWhen JS runs code, it creates execution contexts (global, function, eval).
Conceptually includes:
- Variable environment (bindings)
- Scope chain
thisbinding
Practical takeaway: understand hoisting, scope, and this.
Strict mode removes some silent errors and changes defaults.
"use strict";
function f() {
// In strict mode, `this` is undefined for plain calls.
return this;
}
console.log(f()); // undefinedThe call stack tracks active function calls.
function a() {
b();
}
function b() {
c();
}
function c() {
return;
}
a();Too-deep recursion => stack overflow.