Simple JavaScript challenge 🧑💻 What will be the output of this code? for ( var i = 0; i < 3; i++ ) { setTimeout( () => { console.log( i ); }, 0 ); } What's your answer? And why? #JavaScript #WebDevelopment #Frontend
Md Nahidul I.’s Post
More Relevant Posts
-
*JavaScript Hoisting Tip* In JavaScript, variables and functions are hoisted to the top of their scope. before code execution. ✔ "var" is hoisted and initialized with **undefined** ✔ "let" and "const" are hoisted but stay in the **Temporal Dead Zone** until declared. # Best practice: Always declare variables at the top of your scope to avoid unexpected bugs. #JavaScript #WebDevelopment #Frontend #CodingTips
To view or add a comment, sign in
-
-
Simple JavaScript problem. Clean solution. Find unique characters in a string 👇 Most developers write extra logic for simple problems. The language already gives you tools. You just need to use them properly. How would you solve this WITHOUT using Set? #JavaScript #WebDevelopment #CodingTips #Frontend #Developers
To view or add a comment, sign in
-
-
React is killing complex logics day by day more better code optimization and better performance New React pattern (use() + async support): #ReactJS #FrontendDevelopment #WebPerformance #LearningInPublic #JavaScript #Consistency
To view or add a comment, sign in
-
-
❓ Ever wondered why JavaScript sorts numbers “wrong”? Try this: [1, 10, 2].sort() Output: [1, 10, 2] Wait… why not [1, 2, 10]? 🤯 🧠 The reason: By default, JavaScript’s .sort() converts numbers into strings and sorts alphabetically. So it compares: "1", "10", "2" And "10" comes before "2". Sneaky default behavior 👀 ✅ The fix: arr.sort((a, b) => a - b) Now JS knows it’s numeric sorting. Tiny detail. Big difference. Sometimes bugs aren’t errors — they’re misunderstood defaults 😌 #JavaScript #WebDevelopment #CodingJourney #Frontend #Developers
To view or add a comment, sign in
-
Things wish knew when I started frontend: -The browser is your best debugging tool. Learn DevTools deeply. - CSS isn't broken. You just don't understand the box model yet. - JavaScript fundamentals matter more than any framework. -Your first 10 projects will be ugly. Ship them anyway. Number 4 is the one most people skip. #Frontend #WebDevelopment #JavaScript #CSs #DevLife #SoftwareEngineering Serah ABIJO
To view or add a comment, sign in
-
-
POV: You install one “small” npm package. Your project: 😌 Your node_modules: 🔥🔥🔥 We don’t install dependencies in JavaScript… We adopt their entire family tree. And somehow we still say, “It’s lightweight.” #JavaScript #ReactJS #NodeJS #WebDevelopment #Frontend #ProgrammingHumor
To view or add a comment, sign in
-
-
What is Zone.js, the security camera analogy, 3-step how it works, setTimeout & HTTP real examples... #Angular #ZoneJS #TypeScript #Frontend #WebDevelopment #ChangeDetection #AngularPerformance #JavaScript #FrontendDeveloper #SoftwareEngineering #100DaysOfCode #WebDev
To view or add a comment, sign in
-
-
The React Compiler removes the boilerplate that used to confuse our components. No more useMemo. No more useCallback. Just pure, readable JavaScript. The future of #React is all about developer velocity. #React #NextJS #WebDevelopment #Frontend #JavaScript
To view or add a comment, sign in
-
-
JavaScript Event Loop – Quick Example Understanding the Event Loop is important for writing efficient asynchronous JavaScript. Example: console.log("Start") const prom = new Promise((res) => res(true)) setTimeout(() => console.log("setTimeout"), 0) process.nextTick(() => console.log("nextTick")) queueMicrotask(() => console.log("microtask")) console.log(prom) Output order will be: Start Promise { true } nextTick microtask setTimeout Why? Because JavaScript processes tasks in this order: 1. Synchronous code 2. Microtasks (nextTick, Promises, queueMicrotask) 3. Macrotasks (setTimeout, setImmediate) Understanding this helps when debugging async issues in frontend apps. #javascript #webdevelopment #frontend #vuejs #eventloop
To view or add a comment, sign in
-
💡 Built a mini Todo List in JavaScript! • Add tasks ✅ • Mark them as completed ✔️ • Delete tasks ❌ • Interactive and animated ✨ A fun way to practice DOM manipulation, events, and JS arrays. Perfect for sharpening frontend skills! 🚀 #JavaScript #Frontend #WebDevelopment #Coding #LearnToCode #MiniProject #DOM #Interactive
To view or add a comment, sign in
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
Nice and simple but tricky challenge My answer is: 3 3 3 This happens because var has function scope, not block scope. The loop runs completely first and the value of i becomes 3. The setTimeout callbacks run later, and they all use the same final value of i, which is 3. If we use let instead of var, then it would print 0, 1, 2 because let creates a new value of i for each loop. If you have any other easy explanation, please share. I would love to learn more. Thanks for sharing this interesting question.