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

Vocabulary Around Variables and Scope

This document provides a summary of key vocabulary terms around variables and scope in JavaScript, including: - Variable declaration, initialization, and assignment - Global, functional, and lexical scope - The scope chain and how the JavaScript engine looks for variables in nested scopes - How variables declared with var are hoisted to the top of their scope

Uploaded by

Madan Chaudhary
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)
58 views

Vocabulary Around Variables and Scope

This document provides a summary of key vocabulary terms around variables and scope in JavaScript, including: - Variable declaration, initialization, and assignment - Global, functional, and lexical scope - The scope chain and how the JavaScript engine looks for variables in nested scopes - How variables declared with var are hoisted to the top of their scope

Uploaded by

Madan Chaudhary
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