Here’s something interesting about JavaScript’s single-threaded nature. If you run a long synchronous task (like a 10-second while loop), the UI freezes. During that time, if you click a button multiple times, nothing appears to happen. But when the loop finishes, all the clicks suddenly fire. Why? Because JavaScript is blocked — but your Operating System isn’t. Here’s what actually happens: Your mouse click sends a hardware interrupt to the OS. The OS records it in its input buffer. The browser receives the event and places it into the Macrotask Queue. The Event Loop cannot process the queue until the Call Stack is empty. When the synchronous task completes, the Event Loop finally runs again and processes all queued click events. JavaScript is single-threaded. The system underneath it is not. Understanding this explains many “weird” UI behaviors. #JavaScript #WebDevelopment #EventLoop #Programming
JavaScript's Single-Threaded Nature and UI Freezing
More Relevant Posts
-
JavaScript does NOT use classical inheritance. It uses Prototype inheritance. Example: function Person(name) { this.name = name; } Person.prototype.sayHi = function() { console.log("Hi " + this.name); }; const p1 = new Person("Prakhar"); p1.sayHi(); How it works: JavaScript creates empty object Links it to Person.prototype Assigns this Returns object If property not found on object, JavaScript looks up the prototype chain. This is how inheritance works internally. Understanding prototypes makes debugging easier. #javascript #webdevelopment #frontend #programming
To view or add a comment, sign in
-
🐞 A tiny JavaScript mistake that can break your code. Look at this snippet: function check(){ let first = 1; let First = 1; let res = 0; if(first == First){ res = 1; return res; } } console.log(res); Looks simple, right? But running this code will throw a ReferenceError. Here’s why 👇 🔹 JavaScript is case-sensitive first and First are two different variables. 🔹 Function scope matters res is declared inside the function, so it cannot be accessed outside of it. That’s why this line fails: console.log(res); ✅ Correct way: const result = check(); console.log(result); 💡 Lesson: Most bugs in programming aren't complex algorithms — they’re small details like scope, naming, and function usage. And those details matter. What’s the smallest bug that cost you the most debugging time? 👨💻 #JavaScript #CodingTips #WebDevelopment #Programming #DeveloperLife
To view or add a comment, sign in
-
-
💡 Debounce vs Throttle in JavaScript – A concept every developer should know! Many developers confuse Debounce and Throttle, but understanding the difference can significantly improve application performance. 🔹 Debounce waits until the user stops triggering an event before executing the function. Perfect for: • Search inputs • Autocomplete • API calls 🔹 Throttle ensures a function runs only once within a fixed time interval. Perfect for: • Scroll events • Resize events • Continuous button clicks ⚡ Choosing the right technique helps reduce unnecessary function calls and improves user experience. 📌 Simple rule: Debounce → Wait for inactivity Throttle → Limit execution frequency #JavaScript #WebDevelopment #FrontendDevelopment #CodingTips #Developer #Programming
To view or add a comment, sign in
-
-
JavaScript behavior that looks completely wrong: console.log([] + []); Output: "" Why? Because + triggers type coercion. Step 1: Both arrays are converted to primitive values. [].toString() → "" Step 2: Now it becomes: "" + "" Which equals: "" Now look at this: console.log([] + {}); Output: "[object Object]" Why? [].toString() → "" {}.toString() → "[object Object]" So it becomes: "" + "[object Object]" Understanding coercion rules prevents unpredictable bugs. JavaScript is simple. Its edge cases are not. #javascript #webdevelopment #programming #frontend #softwareengineering
To view or add a comment, sign in
-
Making websites interactive with DOM Manipulation 💻✨ Today's focus is on how JavaScript connects logic with the user interface through the DOM: ✔ Selectors (getElementById, querySelector) ✔ Modifying content (innerText, HTML, styles) ✔ Events (event listeners, bubbling) ✔ Traversing the DOM (parent, child, sibling) Understanding DOM manipulation is a key step toward building dynamic and responsive web applications. Learning step by step and improving every day 🚀 #learning #javascript #dommanipulation #webdevelopment #frontend #programming #developerlife #techskills #logicbuilding #selfimprovement
To view or add a comment, sign in
-
-
Predict the output: function test() { console.log(a); var a = 10; } test(); Output: undefined Why? Because of hoisting. JavaScript rewrites it internally as: function test() { var a; console.log(a); a = 10; } Only declaration is hoisted. Not initialization. Now try with let: function test() { console.log(a); let a = 10; } This throws an error. Because let has temporal dead zone. Understanding hoisting prevents subtle bugs. #javascript #frontend #webdevelopment #programming
To view or add a comment, sign in
-
😵 This one line in JavaScript can trick you! let a = 10; let b = a++; console.log("Addition", a + b, "a = ", a, "b = ", b) At first glance, you might expect both values to be the same… right? 🤔 But JavaScript has its own way of handling this. 👉 Why does b get 10 instead of 11? 👉 When exactly does the increment happen? 👉 And how is this different from ++a? This small concept can lead to big bugs if you misunderstand it. I’ve broken it down clearly in my latest video 🎥 Watch it once — you’ll never get confused again. #JavaScript #Frontend #WebDevelopment #Coding #LearnJavaScript
To view or add a comment, sign in
-
🚀 JavaScript Tips Many developers use var, let, and const every day. But the differences between them can still cause confusion. Here’s the simple idea: • var → function scoped • let → block scoped • const → block scoped and cannot be reassigned Because of this: • var can create unexpected bugs • let is better for variables that change • const should be the default choice In modern JavaScript, most developers follow this rule: 👉 Use const by default 👉 Use let when the value needs to change 👉 Avoid var I made a quick carousel to explain it simply 👇 Which one do you use most in your projects? #javascript #webdevelopment #frontend #programming #developers
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