🔧 Programmierung[$] Stabilizing Rust's never type(08.09.2026 um 15:34 Uhr)
🕵️ SicherheitslückenForgejo 16.0.4 and 15.0.8 address critical security vulnerability(10.09.2026 um 22:05 Uhr)
🔧 AI Nachrichten Canonical joins the Open Secure AI Alliance(03.09.2026 um 03:02 Uhr)
🔧 AI Nachrichten Alberta Tech: I built an app to get my boss to listen to me(27.08.2026 um 16:41 Uhr)
🔧 Programmierung[$] Stabilizing Rust's never type(08.09.2026 um 15:34 Uhr)
🕵️ SicherheitslückenForgejo 16.0.4 and 15.0.8 address critical security vulnerability(10.09.2026 um 22:05 Uhr)
🔧 AI Nachrichten Canonical joins the Open Secure AI Alliance(03.09.2026 um 03:02 Uhr)
🔧 AI Nachrichten Alberta Tech: I built an app to get my boss to listen to me(27.08.2026 um 16:41 Uhr)

🔧 Programmierung 🕛 vor 1 Jahr 2 Min Lesezeit
0

Hoisting in JS

↗ Quelle (dev.to)
🗣️ Stimme:

In JavaScript, we can access the variables and functions even before they are initialized or assigned a value.



Look at the code below:




CODE
greet(); //JavaScript
console.log(x);//Undefined
function greet(){
console.log("JavaScript")
};
var x = 28;






In many other programming languages, this would result in an error. However, in JavaScript, this code runs without any error. JavaScript executes code line by line, but before execution, memory is allocated for all variables and functions. During the two phases—Memory Creation and Code Execution—the Memory Creation Phase assigns undefined to variables(x) and stores the entire function code(greet()) in memory. Here, we are trying to access greet even before it is initialized (We can access the function anywhere before it is initialized). If we remove (x = 28), it will result in an Uncaught ReferenceError: x is not defined.




CODE
console.log(greet); //ƒ greet(){console.log("JavaScript");}
console.log(x);//Uncaught ReferenceError: x is not defined
function greet(){
console.log("JavaScript");
};






Hoisting is the concept of moving declarations to the top of their scope during the compile phase, before the code is executed. Declaring a variable or function means creating or defining its name so that the JavaScript engine recognizes its existence. Initialization refers to assigning a value to a declared variable or defining the code inside a function. In JavaScript, var is hoisted. However, only the declaration is hoisted, not the initialization.




CODE
greet(); //Declaring a function
var x; // Declaring a variable
console.log(x);//Undefined
function greet(){
console.log("JavaScript")
};
x = 28;// Initializing a variable









CODE
greet()
var greet = () => {
console.log("JavaScript");
}; //Uncaught TypeError: greet is not a function






When we run this code, we will get an error. This will happen because, during the memory creation phase, greet will be assigned undefined, as it will be treated as a variable.



Credits to Akshay Saini.

Vollständiger Original-Bericht
Ausführliche Details, Code-Beispiele & Hersteller-Stellungnahme auf dev.to.
↗ Original-Artikel auf dev.to lesen
Wie bewertest du diesen Beitrag?
1 Klick Feedback
Teilen mit Netzwerk & Team:

Community-Analysen & Experten-Meinungen 0

Verfasse deine eigene Analyse, teile Workarounds oder diskutiere diesen Vorfall im Blog.
Noch keine Community-Analyse verfasst. Markiere einen Textabschnitt oder klicke oben auf Eigene Analyse verfassen“!
Community Pulse: Relevanz-Einschätzung
1 Klick Experten-Votum
🔴 Akute Relevanz 0%
🟡 In Evaluierung 0%
🟢 Keine Auswirkung 0%
Spannende Innovation 0%
Verwandte Story-Cluster & Quellen (Vektor-KI)
Port 8095 Engine
1 Quelle
Sony FE 8-14 mm F3.5: Fisheye mit Zirkular-Diagonal-Zoom im Test
1 Quelle
KI-Modell für den Mond: Open-Source-Projekt soll Wasser-Eis finden
1 Quelle
Kirby and the World Beyond: Neues 3D-Abenteuer startet Anfang 2027
Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten Hoisting in JS

Thematisch verwandte Begriffe: Hoisting · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...