🤔 Quick JavaScript Challenge! What does this return? 0.1 + 0.2 === 0.3 If your answer is true, you might want to sit down for this one 😄 👉 It actually returns false. 0.1 + 0.2 // 0.30000000000000004 💡 Why does this happen? JavaScript uses floating-point arithmetic (IEEE-754) to store numbers. Some decimals like 0.1 and 0.2 can’t be represented exactly in binary, so they’re stored as very close approximations. When added together, the tiny errors show up. It’s not a bug — it’s how computers handle floating numbers! 🚀 What this teaches us as developers ✅ Never blindly trust floating-point math ✅ Use rounding when needed (toFixed, Math.round) ✅ Compare with a tolerance (Number.EPSILON) ✅ For finance apps, store values as integers (like cents) Math.abs((0.1 + 0.2) - 0.3) < Number.EPSILON 😄 Fun thought: If 0.1 + 0.2 isn’t 0.3, imagine what other “simple truths” in coding are secretly complicated. That’s what makes programming fun — always something new to learn! #ReactJS #JavaScript #WebDevelopment #Frontend #MERN #ReactHooks #CleanCode #JavaScript #WebDevelopment #FrontendMagic #CodeWithFun #TechExplainedSimply #mernstack #mern #react #js #JavaScript #WebDevelopment #CodingHumor #FrontendDevelopment #TechEducation #ProgrammingFun #LearnToCode #CodeNewbie #DeveloperCommunity
JavaScript Floating Point Math Gotchas
More Relevant Posts
-
🚀 Starting my 30 Days of JavaScript – Logical Thinking Series. Goal: Improve problem-solving skills by building one small project every day. Day 1: Rock Paper Scissors Game 🎮 Built using conditional logic and random value generation. Here code: let playGame = confirm("Shall we play rock, paper, or scissors?"); if (playGame) { //play let playerChoice = prompt("Please enter rock, paper, or scissors."); if (playerChoice) { let playerOne = playerChoice.trim().toLowerCase(); if ( playerOne === "rock" || playerOne === "paper" || playerOne === "scissors" ) { let computerChoice = Math.floor(Math.random() * 3 + 1); let computer = computerChoice === 1 ? "rock" : computerChoice === 2 ? "paper" : "scissors"; let result = playerOne === computer ? "Tie game!" : playerOne === "rock" && computer === "paper" ? `playerOne: ${playerOne}\nComputer: ${computer}\nComputer wins!` : playerOne === "paper" && computer === "scissors" ? `playerOne: ${playerOne}\nComputer: ${computer}\nComputer wins!` : playerOne === "scissors" && computer === "rock" ? `playerOne: ${playerOne}\nComputer: ${computer}\nComputer wins!` : `playerOne: ${playerOne}\nComputer: ${computer}\nplayerOne wins!`; alert(result); let playAgain = confirm("Play Again?"); playAgain ? location.reload() : alert("Ok, thanks for playing."); } else { alert("You didn't enter rock, paper, or scissors."); } } else { alert("I guess you changed your mind. Maybe next time."); } } else { alert("Ok, maybe next time."); } #JavaScript #WebDevelopment #LearningJourney #30DaysOfCode #Frontend
To view or add a comment, sign in
-
Starting with the basics to create strong developers 💻✨ These are the topics I focused on in JavaScript Fundamentals & Logic, the core building blocks that every programmer must master: ✔ Variables (var, let, const) ✔ Data Types (Primitive vs Reference) ✔ Operators (Arithmetic, Logical, Ternary) ✔ Control Flow (if/else, switch, loops) ✔ Functions (declarations, expressions & arrow functions) You can’t skip fundamentals — they shape how you think and how you code. Step by step, learning and improving 🚀 #learning #javascript #programming #webdevelopment #developerlife #techskills #logicbuilding #frontend #selfimprovement
To view or add a comment, sign in
-
-
I used to think bit manipulation was just for "low-level" C++ devs or for those 3:45 AM LeetCode sessions where I’m trying to optimize a "Hard" problem down to O(1) space. 🧘♂️💻 Then I saw how modern libraries like React handle component states and feature flags using bitmasks. It’s not just "math magic"—it’s about: ✅ Performance: Operations that execute in a single CPU cycle. ✅ Efficiency: Packing dozens of boolean flags into a single integer. ✅ Precision: Handling state transitions with zero overhead. I've put together a "Toolbox" of the most handy bit manipulation tricks I've found useful in modern Web Development. Inside the post: 🔹 The "Laser Pointer" analogy for setting bits. 🔹 Why n & (n - 1) is the cleanest way to check for powers of 2. 🔹 The "Brian Kernighan" algorithm for counting set bits. 🔹 Crucial: The 32-bit signed integer "gotcha" in JavaScript. Read the full deep-dive on Dev.to: 🔗 [https://lnkd.in/gsXt682P] Bit manipulation is a power tool. Used wisely, it makes your code lean. Used poorly, it breaks the KISS principle. How often do you use bitwise operators in your day-to-day (outside of competitive programming)? Let’s discuss! 👇 #TypeScript #WebDevelopment #Programming #ReactJS #Performance #SoftwareEngineering #LeetCode #devto
To view or add a comment, sign in
-
⚡ Ever wondered why your JavaScript code runs in a specific order? The answer lies in something called the Call Stack. Every time a function runs, JavaScript adds it to the stack. When the function finishes, it gets removed. Simple rule it follows: 📦 LIFO — Last In, First Out That means the last function added is the first one removed. 🚨 And yes… That scary error — “Maximum call stack size exceeded” It happens when functions keep getting added to the stack without stopping. Eventually, memory fills up… and the program crashes. 🎯 Why understanding the Call Stack matters: ✔ Helps you understand execution order ✔ Makes debugging easier ✔ Builds strong recursion fundamentals ✔ Makes you interview-ready Mastering the Call Stack is one of the first real steps toward truly understanding JavaScript. #JavaScript #WebDevelopment #FrontendDeveloper #Programming #LearnToCode #Developers #Tech
To view or add a comment, sign in
-
-
🔥 JavaScript Full Cheat Sheet (2025 Edition) – Everything in One Place! From basics to advanced concepts, this 8-page guide covers: ✅ Variables (var, let, const) ✅ Data Types & Type Checking ✅ Operators & Control Flow ✅ Loops & Functions (Arrow, Default, Rest) ✅ Objects & Arrays ✅ ES6+ Features (Destructuring, Spread) ✅ DOM Manipulation & Events ✅ Promises, Async/Await ✅ JSON & Modules ✅ OOP, Set & Map ✅ Optional Chaining, Nullish Coalescing & More Perfect for beginners revising fundamentals and developers refreshing concepts before interviews. Stop Googling syntax every 10 minutes. Save this. Use it. Master it. 💻⚡ #JavaScript #WebDevelopment #FrontendDeveloper #FullStackDeveloper #Coding #Programming #LearnToCode #100DaysOfCode #DeveloperLife #TechCommunity #JS #SoftwareEngineering #CodingResources #Developers
To view or add a comment, sign in
-
🚀 𝐓𝐡𝐞 𝐉𝐚𝐯𝐚𝐒𝐜𝐫𝐢𝐩𝐭 𝐋𝐨𝐨𝐩𝐢𝐧𝐠 𝐆𝐮𝐢𝐝𝐞 𝐟𝐨𝐫: The classic. Best when you know exactly how many times you need to run. 𝐟𝐨𝐫...𝐨𝐟: Modern and clean. Perfect for iterating over values in an array or string. 𝐟𝐨𝐫...𝐢𝐧: Use this for objects. It iterates over the keys (properties). 𝐰𝐡𝐢𝐥𝐞: Best when the number of iterations is unknown and depends on a condition. 𝐟𝐨𝐫𝐄𝐚𝐜𝐡(): The functional approach for arrays. Great for readability, though you can't "break" out of it early. // 1. The Standard For Loop for (let i = 0; i < 5; i++) { console.log(`Index: ${i}`); } // 2. For...Of (Best for Arrays) const fruits = ['🍎', '🍌', '🍇']; for (const fruit of fruits) { console.log(fruit); } // 3. For...In (Best for Objects) const user = { name: 'Alex', role: 'Dev' }; for (const key in user) { console.log(`${key}: ${user[key]}`); } // 4. While Loop (Condition-based) let energy = 3; while (energy > 0) { console.log("Coding..."); energy--; } 💡 𝐏𝐫𝐨 𝐓𝐢𝐩: If you are dealing with large datasets and need to transform them, consider array methods like .map() or .filter()—they are often more expressive than a standard loop! Feel free to reach me out for any career mentoring Naveen .G.R|CareerByteCode #javascript #webdevelopment #codingtips #programming #frontend
To view or add a comment, sign in
-
-
Mastering JavaScript: Working with Arrays of Objects Using Reduce Just uploaded a comprehensive multi-page PDF guide on how to effectively handle arrays of objects in JavaScript using the reduce method! 🚀 Whether you're summing values, grouping data by properties, counting occurrences, or merging nested arrays, this guide breaks down these essential patterns with clear examples and practical problems. If you want to write cleaner and more efficient code when working with complex data structures, this is for you! Feel free to download the PDF, try out the examples, and share your questions or insights in the comments. Let’s level up our JavaScript skills together! 💻✨ #JavaScript #CodingTips #WebDevelopment #Programming #CodeNewbie #Developer #LearnToCode #TechGuide #FrontEnd #ReduceMethod
To view or add a comment, sign in
-
Here is the "Cheat Sheet" for the JS essentials: Closures: Why functions remember their surroundings. Async/Await: Making asynchronous code look and feel synchronous. Promises: Handling the future of your data without "callback hell." Prototypes: The secret sauce behind JavaScript's inheritance. The this Keyword: The most misunderstood concept that depends entirely on how you call a function. The Value Add: I’ve found that mastering Closures was the single biggest "Aha!" moment in my career. It changed how I think about data privacy and functional programming. Call to Action (Engagement): Which one of these was the hardest for you to learn? Or is there a 6th concept you think belongs on this list? 👇 Let's discuss in the comments! #JavaScript #WebDevelopment #CodingTips #SoftwareEngineering #TechCareer #Programming
To view or add a comment, sign in
-
-
🚀 Understanding Memoization in JavaScript When working with functions that perform heavy calculations, running the same computation again and again can slow down your application. This is where Memoization becomes very useful. Memoization is an optimization technique where the result of a function is stored after it is executed for the first time. If the function is called again with the same input, the stored result is returned instead of recalculating it. This helps to: ✔️ Reduce unnecessary computations ✔️ Improve performance ✔️ Make applications faster and more efficient In this example, once a value is calculated, it is saved in the cache, so the function doesn’t need to compute it again. In simple terms, Memoization remembers previous results to make future operations faster. It’s commonly used in recursive algorithms, dynamic programming, and performance optimization in JavaScript applications. #JavaScript #WebDevelopment #FrontendDevelopment #Programming #Coding #SoftwareDevelopment #Developers #TechLearning #LearnJavaScript #PerformanceOptimization #CodingJourney #TechCommunity
To view or add a comment, sign in
-
-
😄 JavaScript really said: “So… you thought you understood +?” Let’s clear the confusion properly — no vibes, just fundamentals 👇 🔹 Case 1: Number + Number 2 + 2 // 4 ✅ Simple math. No drama. 🔹 Case 2: Number + String 2 + "2" // "22" ⚠️ + becomes concatenation JS says: “Oh, you want strings? Say less.” 🔹 Case 3: String + String "2" + "2" // "22" 🧩 Pure concatenation. Expected. 🔹 Case 4: Minus operator (-) "22" - 2 // 20 💡 - forces numeric conversion If conversion fails → NaN (not magic, just math rules). 🧠 The real lesson + can add OR concatenate -, *, / only work with numbers JavaScript always tries type coercion Types matter more than intentions 😅 ❌ JavaScript isn’t confusing ❌ Logic isn’t broken ✅ Skipping the basics is. Memes make it funny. Fundamentals make it predictable. 😉 #JavaScript #WebDevelopment #Programming #TypeCoercion #JSBasics #LearnInPublic #Developers #Frontend #JavaScript #Notes #JavaScript #Developer #JavaScript #Mastery #JavaScript #umarhasnain
To view or add a comment, sign in
-
More from this author
Explore related topics
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