⚖️static vs. dynamic scoping
Last updated
Was this helpful?
Last updated
Was this helpful?
Was this helpful?
JS ⟩ concepts ⟩ scope ⟩ static vs. dynamic scoping
When resolving identifier(s),
static scope: cares the where the variable is declared. ( scopes are determined at compile-time❗)
dynamic scope: cares the when the function is invoked. ( the resolving happens at runtime❗)
const { log } = console;
let x = 10;
let y = 20;
// this function needs two variables `x`, `y` to run.
//
// ⭐ static scoping:
// variables are taken from lexical scopes at compile time.
// (in this case, x = 10)