0% found this document useful (0 votes)
2 views19 pages

Scopes 1

The document discusses the concept of scopes in JavaScript, explaining global, function, and block scopes. It highlights how variables are declared and their accessibility based on the scope they are defined in, including the differences between 'var', 'let', and 'const'. Additionally, it touches on the parsing and execution phases of JavaScript, detailing how scopes are maintained during these processes.

Uploaded by

ss5437424
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)
2 views19 pages

Scopes 1

The document discusses the concept of scopes in JavaScript, explaining global, function, and block scopes. It highlights how variables are declared and their accessibility based on the scope they are defined in, including the differences between 'var', 'let', and 'const'. Additionally, it touches on the parsing and execution phases of JavaScript, detailing how scopes are maintained during these processes.

Uploaded by

ss5437424
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/ 19

Scopes

word
what do we mean
by
the
scopes?_?_
→ In
simple words , Slope is
simply where to look

fwthmp what are we


looking for
we are
looking
for variables & functions
have
type of slopes
We less 3 in Js→
more or

① biloba
② function
③ block
Global
scoff

if a variable is
present in a
global slope ,

then it is accessible
everywhere
in the
JSfiᵈ
how
But do we
define a variable in
global
there the
Slope are
many ways
→ one
of way
is

to / define
declare variable outside
any functions
orabl_
functioned
In a
function ,
the
visibility of a variable / fumi
is
just inside the outer
functions
L
function funll
van a = to ; 3 here n is just accessible
inside can
fun or cue
say
3
it is local tuff
Peek Stolpe

In Is we can use a
pair of curly braces to

declare a block .

→ if else 61 .ee
&
: ::
→f1 while

for block
block

} saw
b1
Now
if variable/
fine is
only accessible / visible
"
a

block
inside a then it well he
hang block

Scoff
?⃝
Let / liar , const

var → whenever we use a van


anywhere inside

function gets function seofE


a ,
the variable

if we use it outside a
function ,
matter
no
if
it is enclosed in a block or not
,
it will give the

variable
global Scoff
let → whenever we initiative a valuable with let ,

it
alienage gets the
scope of enclosing B_

if we declare ,
let outside
any
block , then

it does not
get complete global scope
let doesn't allow ieedeclaraticn ,
but var does

allow
let
if you
initiative a variable with outside

block , then also it will not become


any
accessible
completely in the
global scope ,

but
if you
do with var , it will
kg
let)
has block scope (same
const → it also as
,

allow
the
only difference is it doesn't

reassignment
.

const -10
g-
y
= 22 :
Xeric
How JS
, pauses the code_
So we know that JS is not
interpreted ,
it

definitely hybrid compiled interpreted


i. e +
is

So enlcute code
try
whenever we to a JI ,
JS

first pauses the whole code ,


in this
parsing
phase it
assigns Scopes to variables
/fund .

Once done , then it reads the code & executes


variable in code will be used
Every your
in

one
of the
following ways
-

1) either it will be
getting
a vanlue
a
assigned
used
i. e. it is as a
target 2=10

value
2) or it will be used to retrieve a i. e

it well he used Song total


as
y
=

↑ '

console In)
.ly ↑
will
what JS does is
,
it start the
pausing
global
Outside it
phase .

every thing maintains

Sio 're
,

but the moment it


goes
inside a
function
it start:
maintains Sio
;D of that
fund als
ygbbIsooM__

phase I
pausing

+each

score 91cm : ←
→ will just
umʰ
we

do scope
absolution
¥ =

phase 2→executi_

whenever we declare a variable


using var / let/lonst
it is
formal declaration or
initialing afunen is
-

declaration
=
also formal
In the
parsing phase JS looks
for formal
declaration
only
allocate
in Hus
parsing phone we
only
Stolpe values variable
of the
not .

,
=

the moment we
go
in a
fund ,
we maintain a

new
scope as well i e
- -

fund scoff
l¥m# global
phase -1 →
parsing
→ scope of fun
↑ phase -
2. →
eneutn__

p 1
teak

faint .


→ global
-☒-
- -
→ scope off] phase -

=
I -

pansy
-¥ʰ →phaI_
pu
enecutien
team

vi
Case I
"
this was ^

declared outs -

÷
.

a it was
vibhau Case 2 →

declared outside
once inside a
scope ,
we don't know about slope of
a variable we check the outer
sofas are

begat
Autogbobals → In JS
if we
keep an
seemly
variable in outer scopes &
scope of a no

where
fend it
,
we
automatically consider

this
happens deny
global staff
it in

enecuhar
pha#
→ auto
global only works week
target reference
& not
SOI
global
scope

of ten team

✗ ✗✗ erred
☒¥gⁿE
phas#
scope of fun part

Tu#-
sur m
defend
Klint

¥va
&# ʰdefud_

You might also like