0% found this document useful (0 votes)
8 views

js-cheatsheet-Vocabulary around variables and scope-3

The document is a JavaScript cheatsheet focusing on vocabulary related to variables and scope. It explains key concepts such as variable declaration, initialization, assignment, hoisting, and the different types of scope including global, functional, and lexical. Additionally, it outlines the rules governing variable accessibility within nested scopes.

Uploaded by

wingzatari
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

js-cheatsheet-Vocabulary around variables and scope-3

The document is a JavaScript cheatsheet focusing on vocabulary related to variables and scope. It explains key concepts such as variable declaration, initialization, assignment, hoisting, and the different types of scope including global, functional, and lexical. Additionally, it outlines the rules governing variable accessibility within nested scopes.

Uploaded by

wingzatari
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

< > iLoveCoding


JavaScript Cheatsheet
Page 3

Learn JavaScript Correctly (Video course) https://ilovecoding.org/courses/js2

5 Vocabulary around variables and scope


Variable Declaration Scope
var a; The creation of the The limits in which a variable exists. var a = "global";
variable.

function first(){
Global scope
Variable Initialization The outer most scope is called the Global var a = "fresh";
a = 12; The initial scope.
assignment of value
function second(){
to a variable.
Functional scope console.log(a);
Any variables inside a function is in scope }
a = "me"; Variable Assignment of the function.
}
Assigning value to a
variable.
Lexical Environment (Lexical scope) Scope chain
The physical location (scope) where a The nested hierarchy of scope is
console.log(a); Hoisting variable or function is declared is its lexical called the scope chain. The JS
Variables are environment (lexical scope). engine looks for variables in the
var a = "me";
declared at the top scope chain upwards (it its
of the function Rule: ancestors, until found)
automatically, and (1) Variables in the outer scope can be
initialized at the time accessed in a nested scope; But variables
they are run. inside a nested scope CANNOT be accessed
by the outer scope. (a.k.a private variables.)

(2) Variables are picked up from the lexical


environment.
iLoveCoding
"Don't just learn JavaScript - Become a Full-Stack JavaScript Developer" https://iLoveCoding.org

You might also like