I used var for 2 months. Big mistake. var → function-scoped, hoisted, unpredictable 😬 let → block-scoped, reassignable ✅ const → block-scoped, can't reassign ✅ Simple rule: Use const by default. Use let when you need to reassign. Forget var exists. Clean code starts here. 🙌 #JavaScript #WebDev #CodingTips #LearnToCode
var vs let vs const: Choosing the Right Scope
More Relevant Posts
-
JAVASCRIPT NOTES — PART 4 (Core Concepts) This is where JavaScript stops feeling simple. Understanding execution context, closures, and prototypes changes how you read and write code. This post covers: • How execution context actually works • Memory creation & scope chain • Closures and preserved state • Prototype chain & inheritance • Constructor functions vs classes Once these are clear, the language becomes predictable instead of confusing. 📌 Save this for deep revision. #JavaScript #FrontendDeveloper #WebDevelopment #InterviewPrep #LearningInPublic #Closures #Prototypes #Consistency
To view or add a comment, sign in
-
JS is single-threaded. But handles async? The secret → The Event Loop. Call Stack = running NOW Callback Queue = waiting Event Loop = when stack is empty, push from queue That's it. Not magic. Just clever delegation. 🔄 #JavaScript #EventLoop #WebDev #LearnToCode
To view or add a comment, sign in
-
-
JavaScript is single-threaded, but async code doesn’t just run whenever it feels like it. The engine processes: The call stack Then microtasks (Promises) Then macrotasks (setTimeout, etc.) Which means this: console.log("Start"); setTimeout(() => console.log("Timeout"), 0); Promise.resolve().then(() => console.log("Promise")); console.log("End"); Logs: Start End Promise Timeout Even with 0ms, setTimeout waits until the microtask queue is empty. Once I understood that, async bugs stopped feeling random. The event loop isn’t just trivia, it’s how you reason about timing instead of guessing. #JavaScript #EventLoop #AsyncProgramming #WebDevelopment
To view or add a comment, sign in
-
JAVASCRIPT NOTES — PART 5 Some JavaScript bugs aren’t about logic — they’re about understanding how the language behaves internally. This post covers: • Stack vs Heap (how memory is handled) • Shallow vs Deep copy • The real behavior of the `this` keyword • Garbage collection basics • Debouncing & Throttling for UI performance These are the concepts that explain why code behaves the way it does. Once memory and execution flow are clear, JavaScript becomes far more predictable. #JavaScript #WebDevelopment #FrontendDeveloper #InterviewPrep #LearningInPublic #Debouncing #Prototypes #Consistency
To view or add a comment, sign in
-
💡 Built a simple interactive Counter using JavaScript! Features include: Increment & Decrement Reset Save & Load A small project, created for JavaScript practice, and it helped me strengthen my concept in DOM manipulation, event handling, and local storage. #JavaScript #WebDevelopment #Coding #Projects #JSPractice
To view or add a comment, sign in
-
🧠 What is Hoisting? (Explained Simply) JavaScript moves declarations to the top. Example: console.log(a); var a = 5; Output? 👉 undefined Because: JS reads it as: var a; console.log(a); a = 5; Important: var → hoisted with undefined let & const → hoisted but in Temporal Dead Zone Have you ever faced hoisting confusion? 😅 #JavaScript #JSConcepts #Learning
To view or add a comment, sign in
-
-
⚠️ The Danger of Splicing Arrays in a Loop "While solving the 'Move Zeroes' challenge today, I encountered a classic JavaScript pitfall: Modifying an array's length while iterating over it. The Mistake: Using .splice() inside a for loop. When you remove an element, the next one shifts left, and your loop index skips it! The Lesson: Always adjust your index or, even better, use the Two-Pointer technique. It's not just safer; it's much more performant for large datasets. Small bugs teach the biggest lessons! 🚀" "Did you know? JavaScript (ES6) allows you to swap array elements in a single line using destructuring : [a, b] = [b, a]. Clean, readable, and efficient!" Feel free to check out my progress and solutions on my LeetCode profile: I've shared my LeetCode profile link in the first comment below! #JavaScript #CodingTips #WebDevelopment #ProblemSolving #LeetCode #AngularDeveloper
To view or add a comment, sign in
-
-
Learn in Public – Day 14 🚀 Today I spent time understanding callbacks and schedulers properly. Worked with setInterval, setTimeout, and how functions can be passed as arguments...! At first it felt confusing, but after trying small examples it started making sense. It’s interesting how JavaScript can delay or repeat code execution like that. Slow progress, but real progress. 💪 #LearnInPublic #JavaScript #Day14
To view or add a comment, sign in
Explore related topics
- Coding Best Practices to Reduce Developer Mistakes
- Writing Functions That Are Easy To Read
- How to Add Code Cleanup to Development Workflow
- Ways to Improve Coding Logic for Free
- How to Improve Code Maintainability and Avoid Spaghetti Code
- How to Modify Existing Code Confidently
- How to Write Clean, Error-Free Code
- Intuitive Coding Strategies for Developers
- How to Refactor Code Thoroughly
- How to Write Maintainable, Shareable Code
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