Zum Hauptinhalt springen
Echtzeit-Radar & Feeds
Alle RSS Feeds ➔
👥 Community & Social
Sicherheitslücken (CVE)USN-8851-2: Linux kernel (Raspberry Pi) vulnerabilities(02.10.2026 um 08:30 Uhr)
•
Linux Tipps & HardeningUSN-8816-4: Linux kernel (GKE) vulnerabilities(02.10.2026 um 08:30 Uhr)
••
AI & KI NachrichtenThe Truth About Vibe Coding(02.10.2026 um 08:27 Uhr)
••
Sichere ProgrammierungCrisisIQ: An AI Agent for Real-Content Incident Investigation(02.10.2026 um 08:28 Uhr)
•
Sichere ProgrammierungHow to secure a Jakarta EE client application with OIDC (using pac4j)(02.10.2026 um 08:28 Uhr)
••
Sichere ProgrammierungSeven green checks and a team page that named its judges(02.10.2026 um 08:29 Uhr)
••
Sicherheitslücken (CVE)USN-8851-2: Linux kernel (Raspberry Pi) vulnerabilities(02.10.2026 um 08:30 Uhr)
•
Linux Tipps & HardeningUSN-8816-4: Linux kernel (GKE) vulnerabilities(02.10.2026 um 08:30 Uhr)
••
AI & KI NachrichtenThe Truth About Vibe Coding(02.10.2026 um 08:27 Uhr)
••
Sichere ProgrammierungCrisisIQ: An AI Agent for Real-Content Incident Investigation(02.10.2026 um 08:28 Uhr)
•
Sichere ProgrammierungHow to secure a Jakarta EE client application with OIDC (using pac4j)(02.10.2026 um 08:28 Uhr)
••
Sichere ProgrammierungSeven green checks and a team page that named its judges(02.10.2026 um 08:29 Uhr)
••
Intelligence View
⚡ tsecurity.de Intelligence

4 Habits to Avoid Bugs related to Hoisting in your JavaScript Code

1. Declaring variables at the beginning of the scope By declaring variables at the beginning of the scope you ensure that these variables are accessible…

Beitrag
0
Seite
0
↗ Quelle (dev.to)
Social ReaktionenReagiere als Erste:r — dein Feedback zählt!




1. Declaring variables at the beginning of the scope



By declaring variables at the beginning of the scope you ensure that these variables are accessible throughout that scope, avoiding any confusion caused by hoisting.




const data = 12;
const variable = "some data";

// other code










2. var ❌ let and const ✅



Use let and const instead of var to declare or initialize variables. Unlike var, variables created with let and const are not hoisted.



let and const are only accessible within the block they are declared in. This eliminates the possibility of issues of hoisting by variables declared with var.



Example:




 // returns undefined since only the declaration is hoisted
console.log(a);

// hoisted
var a = 19;

// ReferenceError: Cannot access 'b' before initialization
console.log(b);

// did not get hoisted
const b = 12;










3. "use strict" mode



Enabling strict mode directive at the beginning of your code can prevent some hoisting-related problems.



"use strict";



In strict mode, using an undeclared variable throws an error.






4. Use arrow functions and expressions inside a block scope



Using arrow functions and expressions in block scope instead of normal functions.



Function declarations are hoisted along with their entire definition meaning you can call a function before its declaration in the code.



Arrow functions and expressions are defined at the point of use, eliminating confusion. Since they are not hoisted they don't create any errors.



Example:




function setData() {
// Calling the function before declaration throws error
// Error: Cannot access 'myFunc' before initialization
myFunc();

// Using arrow function
const myFunc = () => {
console.log("This is a function expression!");
}
}

setData();










Conclusion



If you found this blog post helpful, please consider sharing it with others who might benefit. You can also follow me for more upcoming content on JavaScript, React, and other Web Development topics.



For paid collaboration, you can mail me at: gmail



Connect with me on Twitter, LinkedIn and GitHub



Thank you for Reading :)

Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten 4 Habits to Avoid Bugs related to Hoisting in your JavaScript Code

Thematisch verwandte Begriffe: Habits, Avoid, Bugs, related · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

💬 Kommentare werden geladen…
Zum Aktualisieren ziehen
tsecurity.de Icon
Offline-Lesen, Eilmeldungen & 0ms Ladezeit

Installiere tsecurity.de direkt auf deinen Home-Bildschirm für das ultimative Vollbild-Magazinerlebnis ohne Browser-Leisten.

Nächster Beitrag