Skip to main content

Command Palette

Search for a command to run...

⚡ Tip: const Doesn’t Mean “Constant” in JavaScript

Published
•1 min read•View as Markdown
N

🚀 Aspiring Full-Stack Developer Blogger 👨‍💻 Passionate about web development and coding. ✍️ Sharing my journey through tech via CodeOdyssey 🌍 "The code is a journey, not a destination."

Many beginners assume:

"const means the value can never change."

But that’s not exactly true.


✅ What const Really Means

  • const prevents reassignment of the variable identifier.

  • It doesn’t make the value itself immutable.

Example:

jsCopyEditconst user = { name: "Nora" };
user.name = "Lina"; // ✅ This works!

But:

jsCopyEdituser = { name: "Ali" }; // ❌ Error: Assignment to constant variable

🔐 If You Want to Freeze the Value

Use Object.freeze():

jsCopyEditconst settings = Object.freeze({ darkMode: true });
settings.darkMode = false; // ❌ No effect

Note: Object.freeze() is shallow — it won’t freeze nested objects.


🧠 Quick Recap

KeywordReassign?Mutable?
var✅✅
let✅✅
const❌✅ (unless frozen)

💡 Pro Tip: Use const by default. Only use let when reassignment is needed.

More from this blog

🔥 كيف ترجع للبرمجة بعد انقطاع طويل؟ دليل عملي لأي شخص “ضاع الطريق” لفترة

الرجوع للبرمجة بعد فترة انقطاع مش شيء سهل… بس كمان مش مستحيل.الأهم إنك مو وحدك: آلاف المبرمجين مرّوا بنفس التجربة — بعضهم رجع أقوى من الأول. هذا المقال يخليك تعرف وين تبدأ، كيف ترجع بسرعة، وكيف تتجنب الإحباط. ⭐ 1. أول خطوة: سامح نفسك وتقبل الواقع أك...

Dec 3, 20252 min read4
C

CodeOdyssey

53 posts

"Welcome to Code Odyssey! A place for passionate developers to find insights, tutorials, and articles on programming, web development, you'll find useful content in both Arabic and English."