Lexial scope (hay static scope) là nơi mà biến được định nghĩa.

Important

Chỉ những đoạn code có cùng lexical scope với một biến hoặc có scope nhỏ hơn thì mới có thể truy cập đến biến đó.

Xét ví dụ sau:

function createCounter() {
	// -> inside createCounter function scope <-
	
	let count = 0
 
	function increase() {
		return ++count
	}
	
	return increase
}

Lexical scope của hàm increase bao gồm bản thân nó và biến count. Mà cụ thể hơn là function scope của hàm createCounter.

list
from [[Lexical Environment]]
sort file.ctime asc

Resources