You believe const means no changes but wait JavaScript has a little surprise !! When I started learning JavaScript, I thought const means the value can never change. Then I saw this magic… and got confused. 1. First: const with simple values const a = 10; a = 20; This makes sense. We are trying to change the value, and const does not allow that. 2. Now the surprise: const with objects const user = { name: "John" }; user.name = "Dev"; // allowed This works because: user is pointing to an object in memory & const locks the variable, It does NOT lock what’s inside the object. The variable still points to the same object. We are not changing the variable. We are only changing data inside it. So, const stops reassignment, but allows changes inside objects or arrays. Sharing this as part of my learning journey. Comment below if this is something you didn’t know before! #JavaScript #FrontendDevelopment #WebDevelopment #LearnJavaScript #CodingJourney #ProgrammingTips #CodingForBeginners #JSBasics #FrontendDev #LearnInPublic #CleanCode #CodeBetter #100DaysOfCode #DeveloperLife #TechLearning #JSFundamentals
JavaScript const surprises: reassignment and object changes
More Relevant Posts
-
Just published a new blog on JavaScript fundamentals 🚀 Understanding the difference between Function Declarations and Function Expressions is crucial for writing better and more predictable code. In this blog, I’ve explained: ✅ Syntax differences ✅ Hoisting behavior ✅ When to use which ✅ Easy examples for clarity 🔗 Read here: https://lnkd.in/d7g3gAjE Feedback is always welcome! 😊 #JavaScript Chai Aur Code Hitesh Choudhary Piyush Garg Akash Kadlag Jay Kadlag Nikhil Rathore
To view or add a comment, sign in
-
JavaScript T-Class Refresh completed in Chai Aur Code Cohort ☕ Sometimes you don’t need new topics. You need stronger foundations. Took a proper refresh session covering the real core of JavaScript. ↪ Understanding specs and manuals ↪ Browser compatibility basics ↪ Hello World with proper code structure ↪ Strict mode and why it matters ↪ Variables and datatypes clarity ↪ Type conversion and operators ↪ Conditionals and loops logic ↪ Functions and flow control This wasn’t advanced stuff. But this is the stuff that makes everything else easier. Revisiting fundamentals always hits differently. Thanks Akash Kadlag for this amazing class.. Which core topic do you think most developers ignore too early?
To view or add a comment, sign in
-
-
🚀 Day 1 of learning TypeScript — Started from scratch today, diving into the basics of TS. Here's what I picked up on Day 1: ✅ TypeScript is essentially a wrapper on top of JavaScript — it adds a layer, compiles down to .js, and then runs via Node.js ✅ What JS doesn't have (but TS does): → Interfaces → Generics → Abstraction (Abstract classes & Interfaces) → Data-type safety ✅ Primitive Data Types in TS: number | string | boolean | null | undefined ✅ Non-primitive types: object & function — with proper type annotations! ✅ Syntax difference that got me: JS: let age = 97 TS: let age: number = 97 Such a small change, but it makes the code SO much more readable and safe. ✅ Key insight: Even if TS throws a compile-time error, it still generates the .js file — because JS doesn't care about types. The compile-time error is TS doing YOU a favor. 💡 The journey of a thousand lines of code begins with a single type annotation. 😄 Day 1 ✅ — many more to go! #TypeScript #JavaScript #LearningInPublic #Programming #Testing #CodingJourney
To view or add a comment, sign in
-
-
Day 65 — JavaScript Learning 🚀 Today I understood a common confusion: map() vs forEach() At first they look the same… but they solve different problems. forEach() → Just loops It runs a function for every element but does not return a new array const numbers = [1,2,3]; numbers.forEach(n => n * 2); // output: nothing stored map() → Transforms data It creates and returns a new array const numbers = [1,2,3]; const doubled = numbers.map(n => n * 2); console.log(doubled); // [2,4,6] 📌 Rule I learned: If you want a new array → use map() If you just want to run code → use forEach() Small difference, big impact in clean code. #Day65 #JavaScript #WebDevelopment #LearningInPublic #CodingTips
To view or add a comment, sign in
-
-
🚀 Just Published My New Blog! I’ve written a beginner-friendly guide on Control Flow in JavaScript — covering: ✅ What control flow means ✅ if statement ✅ if-else statement ✅ else-if ladder ✅ switch statement If you're learning JavaScript, this will help you understand decision-making in code clearly. 🔗 Read here: https://lnkd.in/d9RNEYNy Feedback is always welcome! 🙌 #JavaScript Hitesh Choudhary Piyush Garg Akash Kadlag Jay Kadlag Anirudh Jwala Chai Aur Code
To view or add a comment, sign in
-
One JavaScript habit that improved my code instantly Earlier, my JavaScript files were long and confusing. Everything was written in one place… and debugging was painful. Then I started using small reusable functions instead of writing everything in one block. Now my code is: 1- easier to read 2-ceasier to understand 3- easier to test 4- easier to reuse Instead of repeating logic, I write it once and call it when needed. This one habit saved me time and reduced bugs in my projects. It reminded me of one thing: Clean code is not about writing more code. It’s about writing better code. Still learning and improving every day 🚀 What coding habit helped you the most? #JavaScript #CleanCode #WebDevelopment #FrontendDeveloper #LearningJourney #CodeTips
To view or add a comment, sign in
-
-
🚀 Day 35/50 – Mastering Loops in JavaScript Today I strengthened my understanding of Loops in JavaScript — one of the most important concepts for writing efficient and dynamic code. 🔁 What is a Loop? A loop is used to execute a block of code repeatedly until a condition is satisfied. 📌 Types of Loops in JavaScript: 1️⃣ for loop – Used when the number of iterations is known. for(let i = 1; i <= 5; i++){ console.log(i); } 2️⃣ while loop – Executes while the condition is true. let i = 1; while(i <= 5){ console.log(i); i++; } 3️⃣ do...while loop – Executes at least once before checking condition. let i = 1; do{ console.log(i); i++; }while(i <= 5); 4️⃣ for...of loop – Used for iterating over arrays. let arr = [10,20,30]; for(let value of arr){ console.log(value); } 5️⃣ for...in loop – Used for iterating over object properties. let obj = {name:"Priyanka", role:"Developer"}; for(let key in obj){ console.log(key, obj[key]); } 💡 Key Learnings: ✔ Loops help reduce code repetition ✔ Choosing the right loop improves performance & readability ✔ Understanding break and continue statements is essential Thanks for mentors 10000 Coders Raviteja T Mohammed Abdul Rahman #Day35 #50DaysOfCode #JavaScript #WebDevelopment #FrontendDeveloper #CodingJourney #LearningEveryday
To view or add a comment, sign in
-
-
Functions are the heart of JavaScript, but how you define them matters more than you might think! I’ve just released a new blog post diving deep into the nuances between Function Declarations and Function Expressions. In this guide, I cover: ✅ Core Syntax – How to write both types correctly. ✅ The "Write Once, Use Anywhere" Philosophy – Why functions are essential for reusable code. ✅ Hoisting & Execution – Understanding the critical differences in how the JS engine handles these functions. ✅ Practical Use Cases – When to choose one over the other in your projects. This post simplifies these concepts using clear language and examples to help you avoid common pitfalls. A huge thanks to Hitesh Choudhary sir and Piyush Garg sir for explaining hoisting and function logic in such a simple, memorable way! Check out the full comparison here: https://lnkd.in/gmvhxbHS #JavaScript #WebDevelopment #Programming #CleanCode #LearningToCode #Hashnode #TechCommunity Akash Kadlag | Jay Kadlag
To view or add a comment, sign in
-
-
Today’s JavaScript session was focused on understanding how functions and objects work together behind the scenes. Key concepts I learned: • How the this keyword works in different contexts • How to control function execution using call(), apply(), and bind() • What happens when methods get detached from objects • How the new keyword creates objects • Function constructors and object creation • Prototype inheritance and how JavaScript shares properties • What polyfills are and why they are important These concepts helped me understand how JavaScript manages context, object creation, and inheritance internally. Every day, my understanding of JavaScript is becoming stronger and deeper. Hitesh Choudhary Piyush Garg Chai Aur Code Jay Kadlag Akash Kadlag Anirudh J. #JavaScript #WebDevelopment #LearningJourney #FrontendDevelopment #ContinuousLearning #ProfessionalGrowth #LearningJourney #Growth #SelfImprovement #Development #100DaysOfCode #Learning #ChaiCode #Cohort #LearnInPublic #Cohort26
To view or add a comment, sign in
-
-
JavaScript Operators Explained! 💻 Ready to dive deeper into the world of coding? Today, we're breaking down one of the most fundamental concepts in JavaScript: Operators. What are Operators? In simple terms, operators are used to perform operations between two values. Whether you're adding numbers or comparing data, operators are the building blocks of your code's logic. #JavaScript #CodingTips #WebDevelopment #LearnToCode
To view or add a comment, sign in
More from this author
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development
Const pretty much means that the *reference* of the variable will not be changed, it does not guarantee if the value will be the same or not!