Hoisting is often described as the process of raising your variable and function declarations to the top of your file so they can be referenced before they are defined. This sounds pretty magical, but it's important to know that your code isn't actually getting physically arranged.
Instead JavaScript creates a type of mental map of where variable and function declarations should be accessible during the compile phase. After JavaScript has registered all your variables and functions, it'll enter the execution phase.
Hoisting can be confusing especially because for each different type of variable and function declarations there's a different default value
For example, var variables are initialized with undefined while let and const variables are different and don't get initialized at all 🙃So you could imagine that if you don't have a strong grasp on hoisting, you can introduce unexpected ReferenceErrors throughout your code.
However, the safest option for hoisting is function declarations since their default values are always their function.
🎬 Subscribe to the channel! - [ Ссылка ]
Temporal Dead Zone Resources:
let statements - [ Ссылка ]
Temporal Dead Zone - [ Ссылка ]
Timestamps:
0:00 Intro
0:38 What is Hoisting?
1:02 JavaScript's Double Code Pass-Through
1:43 Two Key Points About Hoisting
2:14 Hoisting var Variables
4:06 Function Declarations vs Function Expressions
5:04 Hoisting Function Declarations
5:44 Hoisting Function Expressions
6:30 Hoisting let and const Variables
7:11 Temporal Dead Zone 💀
7:57 Why Use Hoisting? - Common Use Case
== Let's Connect ==
🐦 Twitter - [ Ссылка ]
== Who I Am ==
I'm Ijemma, a frontend software engineer currently working in New York City. I make videos on all things JavaScript and, more broadly, frontend web development.
#javascript #webdevelopment #softwareengineer
![](https://s2.save4k.ru/pic/QQkW1KsiCyQ/maxresdefault.jpg)