Understanding var, let, and const in JavaScript

🚀Day 3 of My JavaScript Learning Journey Today I learned about something that looks simple but actually forms the backbone of how JavaScript handles variables — var, let, and const. Here’s what I understood 👇 🔹var → The old-school way. It’s function-scoped and can be redeclared or updated easily (sometimes too easily — which can cause bugs). 🔹let → The modern and safer option. It’s block-scoped and can be updated but not redeclared in the same scope. 🔹const → As the name says, it’s constant. Once assigned, its value cannot be changed or redeclared. Perfect for things that stay the same. 💡 My takeaway: Use let when the value might change, and const for everything else. Forget var — it belongs in history books now. 😅 Small concept, big impact. These little details are what make JavaScript more predictable and cleaner when we start writing real-world code. ➡️ The error in the image is because I have used the same name for variable in the code again. ➡️ I have used that name again by commenting the previous one. #JavaScript #WebDevelopment #LearningJourney #Frontend

  • var, let, and const

To view or add a comment, sign in

Explore content categories