codeburst

Bursts of code to power through your day. Web Development articles, tutorials, and news.

Follow publication

JS Demystified 03— Scope

Misa Ogura
codeburst
Published in
5 min readAug 17, 2017

--

Intro

Test Your Knowledge

1: Hello!
2: undefined
3: Ciao!
4: Hello!

What is Scope?

Example 1
Example 2

Global Scope

Window object, accessed via ‘this’ keyword
Globally scoped variable inside the Window object
Globally scoped variables can be accessed and modified from any other scope

Local Scope

Variables declared inside a function can only be accessed and modified within the same scope
Variables that belong to a scope is confined to that specific scope

Hoisting and Scope

1: Hello!
2: undefined
3: Ciao!
4: Hello!

During the memory creation phase:

During the execution phase:

Wrap-up

--

--

Published in codeburst

Bursts of code to power through your day. Web Development articles, tutorials, and news.

Written by Misa Ogura

Senior Machine Learning Engineer @Healx | Creator of github.com/MisaOgura/flashtorch | Published Scientist | Co-founder of @womendrivendev

Responses (4)

Write a response