Zum Hauptinhalt springen
••
IT Security NachrichtenIT Security News Daily Summary 2026-10-16(16.10.2026 um 23:55 Uhr)
•
Sicherheitslücken (CVE)IT Security News Hourly Summary 2026-10-17 00h : 12 posts(17.10.2026 um 00:00 Uhr)
•
IT Security NachrichtenIT Security News Roundup: 2026-10-16 Evening(17.10.2026 um 00:06 Uhr)
•
IT Security NachrichtenWarning Over High-Risk Vulnerabilities in Widely Used LLM Gateway Tool(17.10.2026 um 00:31 Uhr)
•
AI & KI NachrichtenIT Security News Hourly Summary 2026-10-17 01h : 6 posts(17.10.2026 um 01:00 Uhr)
••
Sicherheitslücken (CVE)CISA Urges Patching Critical Vulnerability in BeyondTrust Remote Support(16.10.2026 um 14:00 Uhr)
•
Malware / Trojaner / VirenNew PEERSTITCH Malware Bypasses Security Checks on Fortinet VPNs(16.10.2026 um 23:37 Uhr)
•••
IT Security NachrichtenIT Security News Daily Summary 2026-10-16(16.10.2026 um 23:55 Uhr)
•
Sicherheitslücken (CVE)IT Security News Hourly Summary 2026-10-17 00h : 12 posts(17.10.2026 um 00:00 Uhr)
•
IT Security NachrichtenIT Security News Roundup: 2026-10-16 Evening(17.10.2026 um 00:06 Uhr)
•
IT Security NachrichtenWarning Over High-Risk Vulnerabilities in Widely Used LLM Gateway Tool(17.10.2026 um 00:31 Uhr)
•
AI & KI NachrichtenIT Security News Hourly Summary 2026-10-17 01h : 6 posts(17.10.2026 um 01:00 Uhr)
••
Sicherheitslücken (CVE)CISA Urges Patching Critical Vulnerability in BeyondTrust Remote Support(16.10.2026 um 14:00 Uhr)
•
Malware / Trojaner / VirenNew PEERSTITCH Malware Bypasses Security Checks on Fortinet VPNs(16.10.2026 um 23:37 Uhr)
•
Intelligence View
⚡ tsecurity.de Intelligence

🧭Beginner’s (and Not-So-Beginner’s) Guide #3 — const vs let (and a bit about var): What Developers Keep Getting Wrong

If you’re learning JavaScript, one of the first questions you’ll face is: 👉 Should I use const or let? And what’s up with this old thing called var? It sounds s…

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

If you’re learning JavaScript, one of the first questions you’ll face is:

👉 Should I use const or let?

And what’s up with this old thing called var?



It sounds simple, right?



But trust me — as a senior dev who’s done countless code reviews and technical interviews, I can tell you:



this is one of those “obvious” things that many developers still get wrong. 😅



So let’s break it down — clearly, practically, and once and for all. 🚀





🔒 const — constant, but not always frozen



When you use const, you’re saying:



“This variable name will always refer to the same thing.”



Example:




const name = "Alice";
console.log(name); // Alice

name = "Bob"; // ❌ TypeError






You can’t reassign a const.

But here’s a fun twist: if it’s an object or array, you can still change its contents 👇




const numbers = [1, 2, 3];
numbers.push(4); // ✅ works
console.log(numbers); // [1, 2, 3, 4]

numbers = [0]; // ❌ can't reassign






💡 const doesn’t make the value itself immutable — only the reference (the “box label”) is fixed.

If you truly need immutability, use Object.freeze(), but note it’s shallow.



✅ Use const by default.

It keeps your code predictable and self-documenting — if something shouldn’t change, make it const.





🔁 let — for things that change



When you do need to reassign a variable, go for let:




let counter = 0;
counter = counter + 1;
console.log(counter); // 1






You can also use let inside blocks (if, for, {}):




if (true) {
let message = "Hello!";
console.log(message); // works here
}

console.log(message); // ❌ ReferenceError






That’s because let is block-scoped — it only exists inside the { } where it was declared.



🧩 Bonus fact:

Both let and const are hoisted, but they live in the Temporal Dead Zone (TDZ) until the code reaches their declaration.

That’s why accessing them too early throws a ReferenceError:




console.log(x); // ❌ ReferenceError
let x = 5;









🚫 var — the old-school way (for history lovers)



Before 2015, JavaScript only had var.

It kind of works like let, but with some weird, legacy behaviors.



Example:




if (true) {
var name = "Charlie";
}
console.log(name); // ✅ still works outside the block!






That’s because var has function scope, not block scope.

You can even access it before the declaration, due to hoisting:




console.log(a); // undefined
var a = 10;






And here’s what function scope really means:




function test() {
if (true) {
var greeting = "Hi!";
}
console.log(greeting); // ✅ "Hi!"
}
test();

console.log(greeting); // ❌ ReferenceError






🧓 Nowadays, we use let and const instead — but it’s still good to know what var does.

You’ll definitely encounter it in older codebases.






🧠 Quick Summary




































Keyword Can Reassign? Scope Hoisted? Use It?
const ❌ No Block ✅ (TDZ) ✅ Default
let ✅ Yes Block ✅ (TDZ) ✅ When value changes
var ✅ Yes Function ✅ (initialized as undefined) 🚫 Avoid (legacy)


💡 Pro Tip



In modern JavaScript projects (especially with ESLint), you’ll often see a rule that says:



“Use const wherever possible.”



That’s not dogma — it’s good hygiene.

It keeps your codebase more predictable and helps tools catch bugs early. 🧘‍♂️






🏁 Wrap Up



So, in short:



🟢 Use const most of the time

🟡 Use let if you really need to change the value

🔴 Avoid var unless you’re maintaining ancient code



Keep your variables tidy, your scope clear, and your code modern! ✨



💬 Your turn:



Do you ever still use var?

Or maybe you’ve seen a weird hoisting bug in the wild?

Drop it in the comments — let’s swap battle stories 👇

Intelligence Digest — kostenlos Täglich die wichtigsten Security-News · jederzeit abbestellbar
Community Rating & Social Proof
⭐ Leser-Wertung
–
Ø / 5.0
Noch keine Leser-Bewertungen
War diese Seite hilfreich?
0
Jetzt Bewertung abgeben
🟢 Niedrig (1-3.9) 🟡 Mittel (4.0-6.9) 🔴 Hoch (7.0-8.9) Kritisch (9.0-10.0)
Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten 🧭Beginner’s (and Not-So-Beginner’s) Guide #3 — const vs let (and a bit about var): What Developers Keep Getting Wrong

Thematisch verwandte Begriffe: Beginners, NotSoBeginners, Guide, const · 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
Nächster Beitrag