Welcome to the fourth edition of this weekly series where we look at the surprising sides of programming languages. Even in times where a growing share of code is generated by AI tools, understanding how a language works under the hood remains both fun and relevant. Knowing why a language behaves the way it does helps you read, debug, and reason about code with confidence. This week we look at JavaScript. JavaScript performs automatic type coercion when operators work on values of different types, silently converting operands so the operation can proceed. The plus operator behaves differently depending on its inputs: if one operand is a string, JavaScript converts the other to a string and concatenates, so 5 + "3" yields 53 instead of 8 or a type error. Subtraction instead converts both operands to numbers, so 5 - 3 is 2. The conversion rules are precisely defined in the specification but complex enough to surprise even experienced developers with edge cases like [] + [] resulting in an empty string or [] + {} resulting in [object Object]. The strict equality operator === was introduced later to help developers avoid unintended coercion. The next concept is the event loop. JavaScript is single-threaded, so it runs one piece of code at a time but still manages asynchronous tasks like network requests, timers, and user input without blocking. It does this through the event loop, which checks if the call stack is empty and then pulls the next task from a queue. When you call setTimeout with a zero delay, its callback goes into the task queue and runs only after the current stack clears, so it executes after subsequent synchronous code. Promises add another layer with a microtask queue, which has higher priority than the regular task queue. Knowing this distinction is key to predicting execution order in asynchronous JavaScript. In JavaScript, all numbers are 64-bit floating point values following the IEEE 754 standard, and there is no separate integer type. As a result, 0.1 + 0.2 does not equal 0.3 but instead yields 0.30000000000000004, not because of a JavaScript bug but due to how binary floating point represents decimal fractions. The value 0.1 cannot be represented exactly in binary, just as one third cannot be written exactly in decimal. This issue affects any language using IEEE 754, but it is more visible in JavaScript because there is no integer type to fall back on for exact whole-number arithmetic. For financial or precision-critical work, developers typically use libraries for arbitrary-precision arithmetic or operate on integers representing the smallest unit, such as cents instead of dollars. Next week, we continue with a different language. #JavaScript #JS #Programming #SoftwareEngineering #CodeCuriosities #DevCommunity
JavaScript's Surprising Sides: Type Coercion, Event Loop, and Floating Point Precision
More Relevant Posts
-
🚀 Understanding OOP in JavaScript 🚀 Object-Oriented Programming (OOP) is a programming paradigm that helps us structure code using objects — making it more organized, reusable, and scalable. In JavaScript, OOP revolves around: Classes & Objects – Templates (classes) to create objects. Encapsulation – Keeping data safe inside objects. Inheritance – Reusing code by extending existing classes. Polymorphism – Methods behaving differently based on context. Abstraction – Hiding complex implementation details. Example: class Person { constructor(name, age) { this.name = name; this.age = age; } greet() { console.log(`Hello, I'm ${this.name}`); } } class Employee extends Person { constructor(name, age, role) { super(name, age); this.role = role; } greet() { console.log(`Hello, I'm ${this.name} and I work as a ${this.role}`); } } const emp = new Employee("Aditya", 24, "Developer"); emp.greet(); // Hello, I'm Aditya and I work as a Developer 💡 Why OOP in JS? Makes code modular and maintainable. Reduces redundancy through inheritance. Simplifies complex projects with abstraction and encapsulation. #JavaScript #OOP #Coding #WebDevelopment #LearnToCode
To view or add a comment, sign in
-
😂 25 JavaScript Moments That Break Developers Mentally Every developer starts learning JavaScript with hope. After a few months… they start laughing like a villain in a movie. 😅 Here are 25 JavaScript moments that mentally break developers: 1️⃣ "NaN !== NaN" → Even JavaScript doesn't trust itself. 2️⃣ "typeof null === "object"" → The bug that never left since 1995. 3️⃣ "0.1 + 0.2 = 0.30000000000000004" → Mathematics crying in the corner. 4️⃣ "[] + [] = """ → Empty + Empty = Nothing. Deep philosophy. 5️⃣ "[] + {}" → ""[object Object]"" → JavaScript poetry. 6️⃣ ""5" - 3 = 2" but ""5" + 3 = "53"" → Math depends on JavaScript mood. 7️⃣ "true + true = 2" → Boolean suddenly becomes math genius. 8️⃣ "false == 0" → true But "false === 0" → false JavaScript: Choose your own reality. 9️⃣ "setTimeout(fn, 0)" → runs later… not now. Patience developer. 🔟 "this" keyword → depends on where, when, how, and who called it. 11️⃣ Forgetting "await" → Promise chaos begins. 12️⃣ Arrow functions + "this" → confusion level upgraded. 13️⃣ Accidentally creating global variables without "let" or "const". 14️⃣ Callback hell → looks like a staircase to coding hell. 15️⃣ Infinite "console.log()" debugging. 16️⃣ "undefined" vs "null" → same… but not same. 17️⃣ "parseInt("08")" behaving weird in older browsers. 18️⃣ "==" vs "===" → one line bug that ruins everything. 19️⃣ "map()" used when you needed "forEach()". 20️⃣ "this" inside event handlers doing unexpected drama. 21️⃣ React re-render loop because of one tiny mistake. 22️⃣ "document.querySelector()" returning null when you swear the element exists. 23️⃣ Accidentally mutating objects. 24️⃣ "JSON.stringify()" removing "undefined". 25️⃣ Finally fixing the bug… but you have no idea how it got fixed. Developer after solving it: «“The code works… please nobody touch it.” 🫡» And that’s the secret truth of the internet: Half the web runs on JavaScript. The other half runs on developers praying it doesn’t break. 🔥 If you’re a developer and felt this pain… welcome to the club. #JavaScript #CodingHumor #ProgrammerLife #DevHumor #WebDevelopment #SoftwareDeveloper #TechHumor #ProgrammerMemes #DeveloperProblems #CodeLife #FrontendDeveloper #BackendDeveloper #100DaysOfCode #ProgrammingLife #StackOverflow #Debugging #CodeNewbie #SoftwareEngineering #BuildInPublic #DevelopersLife #madurai #chennai #fresher #job #career #mumbai #bangalore #delhi #ai #germans
To view or add a comment, sign in
-
Behind every JavaScript feature we use daily, there is a deeper engine running underneath. While exploring OOP in JavaScript, I broke down how classes are just syntactic sugar over the prototype system and even implemented core array behaviors to understand how things work internally. If you want to truly understand the prototype chain and the hidden mechanics of JavaScript, this deep dive might help 👇 https://lnkd.in/dJutzQ6p Thanks to Hitesh Choudhary Sir , Piyush Garg
To view or add a comment, sign in
-
Prototypes in JavaScript (The Secret Behind Everything) JavaScript doesn’t use classical inheritance like Java or C++ 👉 It uses Prototypal Inheritance --- 💡 Every object in JS has a hidden link: "[[Prototype]]" --- ⚡ Example: const animal = { speak() { console.log("Animal speaks"); } }; const dog = Object.create(animal); dog.speak(); // 🐶 Animal speaks --- 🤯 What just happened? - "dog" does NOT have "speak()" - JavaScript looks into its prototype - Finds it in "animal" 👉 This is called the Prototype Chain --- 🧩 Real Magic: [].map === Array.prototype.map // true 👉 That’s why arrays have methods like "map", "filter", etc. --- ⚠️ Important: dog.__proto__ === animal // true But avoid using "__proto__" directly Use "Object.getPrototypeOf()" --- 🚀 Why this matters: - Foundation of JS inheritance - Helps understand classes under the hood - Makes debugging easier --- Reference from 👉 Sheryians Coding School #javascript #webdevelopment #frontend #programming #coding
To view or add a comment, sign in
-
-
🚀 Just published a new blog: 𝗨𝗻𝗱𝗲𝗿𝘀𝘁𝗮𝗻𝗱𝗶𝗻𝗴 𝗢𝗯𝗷𝗲𝗰𝘁-𝗢𝗿𝗶𝗲𝗻𝘁𝗲𝗱 𝗣𝗿𝗼𝗴𝗿𝗮𝗺𝗺𝗶𝗻𝗴 𝗶𝗻 𝗝𝗮𝘃𝗮𝗦𝗰𝗿𝗶𝗽𝘁 If you’ve ever felt confused about classes, instances, `new` keyword, or how OOP actually works under the hood in JS — this one’s for you. I’ve broken it down step-by-step with practical examples, real-world analogies, and code snippets that actually make sense. Whether you’re a beginner trying to level up or an experienced dev looking for a solid refresher, I hope it helps clear things up! 🔗 Read it here: https://lnkd.in/gk4W-7_a Hitesh Choudhary Piyush Garg Akash Kadlag Suraj Kumar Jha Anirudh J. Chai Aur Code Jay Kadlag Nikhil Rathore Happy coding! 💻 #JavaScript #OOP #WebDevelopment #Programming #DeveloperCommunity #TechBlog
To view or add a comment, sign in
-
🚀 JavaScript Simplified Series — Day 3 Programming me kabhi kabhi aisa hota hai ki **data ka type change karna padta hai.** Example: User form me age likhta hai → "25" Lekin JavaScript ise **string** samajhta hai. Agar hume calculation karni ho to? Tab hume string ko **number me convert** karna padega. Isi concept ko kehte hain: **Type Conversion** Example: ```javascript let age = "25" let convertedAge = Number(age) console.log(convertedAge + 5) ``` Output 30 Yaha kya hua? "25" (string) → 25 (number) JavaScript me type conversion do tarah se hota hai: 1️⃣ **Implicit Conversion** JavaScript automatically type change kar deta hai. Example: ```javascript "5" + 2 // "52" ``` 2️⃣ **Explicit Conversion** Hum khud manually convert karte hain. Example: ```javascript Number("10") String(20) Boolean(1) ``` Ab aata hai next important concept. **Operators** Operators wo symbols hote hain jo values par operations perform karte hain. Example: ```javascript let a = 10 let b = 5 console.log(a + b) // Addition console.log(a - b) // Subtraction console.log(a * b) // Multiplication console.log(a / b) // Division ``` JavaScript me mainly operators hote hain: ➤ Arithmetic Operators (+ - * / %) ➤ Comparison Operators (== === > <) ➤ Logical Operators (&& || !) Simple words me: Type Conversion → Data type change karta hai Operators → Data par operations perform karte hain Agar aap JavaScript ko **Hindi me deeply samajhna chahte ho**, to YouTube par in channels ko follow kar sakte ho: • ** Rohit Negi ** • ** Hitesh Choudhary (Chai aur Code)** Waha concepts **simple aur practical way** me explain kiye gaye hain. 📌 Series Progress Day 1 → What is JavaScript Day 2 → Variables & Data Types Day 3 → Type Conversion & Operators Day 4 → Truthy vs Falsy Values Follow karo agar tum **JavaScript ko scratch se master karna chahte ho.** #JavaScriptSimplified #javascript #webdevelopment #coding #programming #learninpublic #100DaysOfCode #frontenddevelopment #devcommunity #codingjourney
To view or add a comment, sign in
-
🦎 reasons I always pick TypeScript over Javascript since I'm coding with AI agents, even for little demos, even for scripts: - yeah TypeScript has overhead. setup, compile step, types to write. but you're using agents to code, so you don't do any of that. the agent does it. so why do you care? - the agent can fix its own mistakes. it runs `tsc`, sees the error, corrects it. in JavaScript you either describe the error back manually, set up some MCP connection or test runner so the agent gets runtime feedback, or rely on test coverage to close the loop. all of that works, it's just more setup and you still need to actually hit the right code path to surface the bug. TypeScript catches it without running anything. - 4x fewer regressions in TypeScript projects (2-3% vs 8-12%, Builder.io 2026). 94% of LLM compilation errors are type-check failures, so the compiler is catching exactly the category of mistakes agents make most often - agents use fewer tokens on TypeScript codebases, in my experience, and the community seems to agree. the reason is pretty simple: a compiler error is precise ("line 42, wrong type") so the agent goes straight to the fix. a JavaScript runtime error requires re-reading context, guessing what caused it, trying again. more iterations, more tokens per bug - types give the agent a map. change an interface and it knows every call site that broke. in JavaScript it's guessing from variable names - even for one-off scripts I don't bother with JavaScript anymore. the debugging is just better. and I'm never sure a script won't grow, so I'd rather start right. my brain defaults to TypeScript now and I don't regret it.
To view or add a comment, sign in
-
🚀 New Blog Posted... Hello Developers 🖐, We often start learning JavaScript by writing code, but many struggle to truly understand what happens behind the scenes. So I wrote a beginner-friendly article explaining the core building blocks of JavaScript: • Variables • Data Types • Scoping • var, let, and const In this article, I break down these concepts in the simplest way possible with visual explanations and practical examples so beginners can understand how JavaScript actually works under the hood. If you're starting your JavaScript journey or revising fundamentals, this will help. 🗒️Read the full article here 👇 : https://lnkd.in/ge26UnkM Feedback from fellow developers is always welcome. Thanks to my mentors for the community & support. Hitesh Choudhary Anirudh Jwala Akash Kadlag Piyush Garg #chaicode #JavaScript #WebDevelopment #Programming #Coding #FrontendDevelopment #LearnToCode
To view or add a comment, sign in
-
🚀 Just published a new blog on Understanding Variables and Data Types in JavaScript. In this article, I explain the basics of variables, why they are needed in programming, and how to declare them using var, let, and const. I also covered important primitive data types like string, number, boolean, null, and undefined with simple beginner-friendly examples. 📖 Read the full article here: https://lnkd.in/gzXWjzJG Inspired by the amazing teaching of Hitesh Choudhary Sir and Piyush Garg Sir from Chai Aur Code. ☕💻 #javascript #webdevelopment #learninginpublic #chaiAurCode
To view or add a comment, sign in
-
🚨 90% React Developers Are Making These Mistakes ⚛️ If you're learning React.js or already building projects, chances are you're making at least one of these mistakes. And trust me — these small mistakes are the reason most developers stay stuck at beginner level. Let’s fix that today 👇 _____________________________ ❌ 1. Not Understanding Core JavaScript React is built on JavaScript. If your JS basics are weak, React will always feel confusing. ______________________________ ❌ 2. Ignoring Component Reusability Writing the same code again & again? You’re missing the whole point of React. ______________________________ ❌ 3. Overusing useEffect Not everything needs useEffect. Using it wrong = bugs + performance issues. ______________________________ ❌ 4. Poor State Management Too many states? Wrong structure? Your app will become messy fast. ______________________________ ❌ 5. Not Using Proper Folder Structure A messy project = hard to scale + hard to debug. _______________________________ ❌ 6. Forgetting Keys in Lists No keys = unexpected UI bugs 😵💫 _______________________________ ❌ 7. Not Building Real Projects Watching tutorials ≠ learning Building projects = real growth 🚀 ______________________________ 💡 Reality Check: Most developers don’t fail because React is hard… They fail because they ignore these fundamentals. ________________________________ 🔥 Pro Tip: Focus on writing clean, reusable, and scalable code — that’s what companies actually want. _________________________________ 👇 CTA Which mistake are YOU making right now? Comment below 👇 I’ll personally help you fix it. 💾 Save this post for revision 🔁 Share with your developer friends ❤️ Follow for more React & MERN content ____________________________________ #reactjs #webdevelopment #frontenddeveloper #javascript #mernstack #codinglife #programming #developer #learnreact #softwaredeveloper #reactmistakes
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