Hoisting in JavaScript
Hoisting is JavaScript's behavior of moving variable and function declarations to the top of their scope during compilation – before code execution.
This means you can use functions and var variables before declaring them in code, but there are important differences with let/const.
Function Declaration Hoisting
Function declarations are fully hoisted – you can call them before defining.
var Hoisting
var declarations are hoisted, but initializations are not – the variable is undefined until assigned.
let and const – No Hoisting (Temporal Dead Zone)
let and const are NOT hoisted in the same way – accessing them before declaration causes ReferenceError (Temporal Dead Zone).
Function Expressions and Hoisting
Function expressions (including arrows) are not hoisted like declarations.
Best Practices
- Always declare variables at the top of their scope.
- Prefer let/const over var.
- Use function declarations when order doesn't matter; expressions for conditional logic.
Quick Quiz
Wir haben die Materialien überprüft, dennoch können Fehler vorkommen. Der Inhalt dient ausschließlich Bildungszwecken, daher verwende ihn auf eigene Verantwortung und überprüfe ihn bei Bedarf mit anderen Quellen.
✨ Frag Lara — deine KI-Lernpartnerin
Entsperre personalisierte Lernunterstützung. Lara kann Lektionen erklären, Themen zusammenfassen und deine Lernfragen beantworten — verfügbar ab dem Go-Tarif.
Lara hilft dir, schneller zu lernen — exklusiv für ReadyTools Go-, Plus- und Max-Mitglieder.


