Scope and Hoisting in ES6 JavaScript

5 min readFeb 25, 2020

Since 2015 Developers implemented a convention called ES6 to better use Javascript code; two ways this has changed is though hoisting and scope.


Scope is what’s available, or the resources one has access to, in any execution of code. When looking at scope, the easiest way to see it in action is through the assignment of variables.

Global, Block, Functional Scope

There are two new ways to assign variables, let and const:

let a = "some"
const b = "variables"
console.log(a,b) //some variables

This is an example of global scope. The variables a and b everywhere in the code are the same value. You can reassign the value of a because it was assigned by let ; the value of b can’t be reassigned because it was assigned by const (short for constant).

a = "all" 
b = "functions"
Thrown: TypeError: Assignment to constant variable.

Without a const or let these variables are also assigned on a global scope.

If we look at how variable assignment works in functional scope, we get to see the value of const and let. If we were interested in knowing the number of chairs in a room, we could create a function like countChairs() :

//node> function countChairs(){... let chairs = 1... console.log("chairs", chairs)... }undefined> countChairs()chairs 1undefined>

We would run into trouble though, if we built any chairs…

//node> function buildChairs(){... chairs = chairs + 1... console.log("chairs",chairs)... }undefined> buildChairs()Thrown:ReferenceError: chairs is not definedat buildChairs (repl:2:1)>

Composer, Designer, Educator