Sitemap

JavaScript Hoisting

2 min readSep 25, 2022

--

Banner Hoisting — JS

Javascript is an interpreted language, it goes line by line executing the code. When declarations are moved to the beginning of the scope, this is known as hoisting.

Get German Mardones’s stories in your inbox

Join Medium for free to get updates from this writer.

In other words, we can call a function and define it further down, because JS will upload the definition of this function to the beginning of the scope.

Function before hoisting

Finally JS does the following

Function after hoisting

In the case of Variables, it only applies in the declaration and not in the assignment, leaving the previous example as follows.

Variables after hoisting

if we were to put the “max” declaration at the end of our code and initialize it with “=3” this would throw us an error.

Subscribe to receive a notification to your email every time I have a new post for you, here

Follow me for weekly guide and posting about Vue, JS, or other tecnologies.

Want to connect? Reach out to me on LinkedIn

--

--