✨ 𝗗𝗮𝘆 𝟰 𝗼𝗳 𝗟𝗲𝗮𝗿𝗻𝗶𝗻𝗴 𝗝𝗮𝘃𝗮𝗦𝗰𝗿𝗶𝗽𝘁 🚀 Today I learned about 𝗖𝗼𝗻𝗱𝗶𝘁𝗶𝗼𝗻𝗮𝗹𝘀, 𝗟𝗼𝗼𝗽𝘀, 𝗮𝗻𝗱 𝗢𝗽𝗲𝗿𝗮𝘁𝗼𝗿𝘀 — the core logic that makes programs think and repeat tasks. But what really surprised me was what happens behind the scenes when we compare values. I discovered why floating-point calculations can be unpredictable in JavaScript. 𝗙𝗼𝗿 𝗲𝘅𝗮𝗺𝗽𝗹𝗲: 𝟬.𝟭 + 𝟬.𝟮 !== 𝟬.𝟯 This happens because JavaScript uses binary floating-point representation (IEEE 754), and some decimal numbers can’t be represented exactly in binary. So tiny precision errors appear. It’s fascinating to see that even simple math has deep computer science concepts behind it. Every day I realize: writing code is one thing, understanding it deeply is another. 💪 #JavaScript #100DaysOfCode #WebDevelopment #LearningJourney #ComputerScience
JavaScript Floating Point Precision Issues
More Relevant Posts
-
Today I practiced the "Middle of the Linked List" problem while working on Data Structures in JavaScript. The challenge was to return the middle node of a singly linked list. If the list has two middle nodes, the second one should be returned. Instead of counting the length of the list first, I implemented the Fast and Slow Pointer technique: Slow pointer moves one step at a time Fast pointer moves two steps at a time When the fast pointer reaches the end, the slow pointer naturally lands at the middle of the list. This approach solves the problem in O(n) time and O(1) space, which is much more efficient than calculating the list length separately. Working through these problems is helping me strengthen my understanding of pointers, traversal patterns, and algorithmic thinking in JavaScript. #javascript #dsa #datastructures #algorithms #leetcode #programming #softwareengineering
To view or add a comment, sign in
-
-
✨ 𝗗𝗮𝘆 𝟱 𝗼𝗳 𝗠𝘆 𝗝𝗮𝘃𝗮𝗦𝗰𝗿𝗶𝗽𝘁 𝗝𝗼𝘂𝗿𝗻𝗲𝘆 🚀 Today I explored 𝗡𝘂𝗺𝗯𝗲𝗿𝘀 𝗮𝗻𝗱 𝘁𝗵𝗲 𝗠𝗮𝘁𝗵 𝗢𝗯𝗷𝗲𝗰𝘁 in JavaScript, and learned some interesting behind-the-scenes details: • 𝗡𝘂𝗺𝗯𝗲𝗿 – integers, floats, NaN, Infinity • 𝗠𝗮𝘁𝗵 𝗢𝗯𝗷𝗲𝗰𝘁 – handy methods like Math.round(), Math.floor(), Math.ceil(), Math.random(), Math.max(), Math.min() • 𝗠𝗮𝘁𝗵.𝗿𝗮𝗻𝗱𝗼𝗺() – generates pseudo-random numbers, which means it’s not truly random. It’s predictable if you know the algorithm and therefore shouldn’t be used for OTPs or secure codes. It’s fascinating to see how much thought goes into even simple math operations in JavaScript. Step by step, my fundamentals are getting stronger! 💪 #JavaScript #100DaysOfCode #WebDevelopment #LearningJourney #FrontendDevelopment #CodingTips
To view or add a comment, sign in
-
-
If you’ve written JavaScript long enough, you’ve seen this: 0.1 + 0.2 === 0.3 // false Instead you get: 0.1 + 0.2 // 0.30000000000000004 And no — it’s not a JavaScript bug. It’s IEEE 754 floating-point math. Just like you can’t represent 1/3 perfectly in decimal, binary can’t represent 0.1 perfectly either. JavaScript (and Python, Java, C, etc.) all use floating-point representation for numbers. So the real lesson isn’t: “JS is weird.” The lesson is: 👉 Never use floats for money. If you’re building anything with payments, invoices, subscriptions, or ledgers: • Store amounts as integers (cents / paise) • Convert only at the UI layer • Or use a decimal library Example: const priceInCents = 1099; // $10.99 const total = priceInCents / 100; Small detail. Massive production impact. This is one of those concepts that separates “it works on my machine” from “this survives scale.” Curious — what’s the most surprising JavaScript quirk you’ve hit in production? If you enjoy practical engineering insights like this, feel free to follow me here 👇 https://lnkd.in/giDBvsgq
To view or add a comment, sign in
-
-
Priority Order in JavaScript Day 216 Today Today I learned about the Priority Queue. It is a very important concept in data structures. In a normal queue the rule is first in first out. But in a priority queue the element with the highest priority is processed first. Think of a hospital emergency room. A patient with a serious injury gets treated before someone with a cold even if the person with the cold arrived earlier. This is exactly how a priority queue works. I learned that there are two ways to implement this. You can use an array and sort it every time but that is slow. The best way is using a Heap. Using a Heap makes adding and removing elements very fast because the time complexity is log n. JavaScript does not have a built in priority queue like some other languages. This means we have to build it ourselves using classes. This is a great way to practice logic building and understand how things work under the hood. A very helpful tip for interviews is that if a question asks for the Kth smallest or Kth largest element you should think of using a priority queue or a heap. It makes the solution much more efficient. Today I solved these LeetCode questions: 215 Kth Largest Element in an Array 703 Kth Largest Element in a Stream #DSAinJavaScript #365daysOfCoding #JavaScriptLogic #LeetCode #DataStructures #PriorityQueue #CodingInterview #ProgrammingDaily #SoftwareEngineering #TechLearning #WebDevelopment #LogicBuilding #ProblemSolving #JavaScriptDev #JSCode #ArrayLogic #HeapDataStructure #AlgorithmDesign #CodingChallenge #BinaryHeap
To view or add a comment, sign in
-
Solved the Flatten a Multilevel Doubly Linked List problem using a Depth-First Search (DFS) approach in JavaScript. Key idea: Traverse the list and whenever a node contains a child pointer, recursively flatten the child list and splice it into the main list while maintaining proper prev and next connections. This problem is a great exercise in pointer manipulation and recursion. It reinforces how important it is to carefully update references when working with linked data structures. Time complexity: O(n) Space complexity: O(d) where d is the recursion depth. #DataStructures #Algorithms #LinkedList #JavaScript #DSA #CodingPractice #LeetCode #ProblemSolving #SoftwareEngineering
To view or add a comment, sign in
-
-
What really happens under the hood of JavaScript shift() and unshift()? Most developers use shift() and unshift() without thinking twice. I recently rebuilt unshift() from scratch to understand the computer science behind it — and the insight is important. What’s happening under the hood JavaScript arrays are indexed collections (0, 1, 2, 3…) Inserting at index 0 means every element must be shifted right We loop backwards to avoid overwriting values This operation runs in O(n) time Built-in behavior (same cost!) arr.unshift(value); O(n) arr.shift(); Even though these methods look simple, they trigger a full re-indexing of the array internally. Why this matters (Core CS insight) Arrays → fast random access O(1) Arrays → slow inserts/deletes at the start O(n) This is why queues often use linked lists or alternative data structure Understanding what happens under the hood helps you write more performant code and make better data structure choices — especially at scale. Sometimes, rebuilding the basics teaches you more than any framework ever will. JavaScript #ComputerScience #DataStructures #WebDevelopment #LearningInPublic #UnderTheHood
To view or add a comment, sign in
-
-
📌 #69 DailyLeetCodeDose Today's problem: 25. Reverse Nodes in k-Group – 👹 Hard Interesting fact about me – linked lists were my favorite topic in the Algorithms and Data Structures course at university. So for the 69th problem I got something special – a hard linked list problem 😈 Honestly, the problem description is written in probably the most confusing way possible. But the core idea is actually pretty simple: you just need to reverse nodes in groups of size k inside the list. In practice, this is only slightly more complicated than reversing the entire linked list – the main difference is that when you reverse a group, you must keep track of the new head of that reversed group so you can correctly reconnect it with the previous and next parts of the list. It may look scary at first glance, but in reality it's not that bad. The most important thing is not to get lost in pointer manipulation 🦍 https://lnkd.in/daAPrhbP #DailyLeetCodeDose #LeetCode #JavaScript #Algorithms #ProblemSolving #Coding
To view or add a comment, sign in
-
-
JavaScript’s sort() can silently break your algorithms. I was solving LeetCode #350 (Intersection of Two Arrays II) using the two-pointer approach and hit an unexpected issue. I sorted the arrays like this: nums.sort() It looked fine… until it wasn’t. Example: [1, 2, 10, 5].sort() // → [1, 10, 2, 5] Why? Because JavaScript sorts lexicographically (as strings) by default. So the engine actually compares: "1", "10", "2", "5" Correct numeric sorting requires a comparator: nums.sort((a, b) => a - b) Without this, algorithms that rely on sorted arrays (binary search, two-pointer techniques, etc.) can produce incorrect results. #JavaScript #WebDevelopment #Programming #CodingTips #LeetCode #Algorithms #SoftwareEngineering #FrontendDevelopment
To view or add a comment, sign in
-
-
From You Don't know JavaScript Part 1 ❌ We know JavaScript Part 1... ✅ Today's T-Class ☕ was all about this : Learning : - Ask Why ?? to understand What and How ? - Object constructor syntax - Object Literal - Property Value shorthand - Looked at refs and Copying with new P.O.V ("Radhika Das => Taylor Swift" 😁) - Cloning Nested Objects - Modifying Objects - Object.assign() - Garbage Collection 🗑️ - "this" as "girgit" - "this" in arrow methods as "glass box" - Suntax of function as Constructor - Optional Chaining - Symbol , Global Symbol - Using Object as Primitve Datatype - Object Wrapper - e 😎... call me if you want to be millionare - A short View on JSON methods , Maps and Sets Thanks Akash Kadlag sir Hitesh Choudhary sir Jay Kadlag Bhaiya #chaicode
To view or add a comment, sign in
-
-
🚀 DSA Practice — Two Pointer Technique I initially thought this problem required Binary Search because the array is sorted. But the real trick was something simpler — the Two Pointer Technique. The problem: Two Sum II (Input Array Is Sorted). Since the array is already sorted, we can place two pointers: left → start of the array right → end of the array Then calculate the sum: sum = numbers[left] + numbers[right] If: sum > target → decrement right sum < target → increment left otherwise → return [left + 1, right + 1] ⚡ Complexity Time Complexity: O(n) Space Complexity: O(1) No extra data structures needed — just pointer movement. 💡 Takeaway Small problems like this reinforce an important lesson: Always look for properties of the input (like sorted arrays). They often unlock a more optimal solution. Would you solve this using Two Pointers, or would you still prefer a HashMap approach? #LeetCode #DSA #Algorithms #TwoPointers #JavaScript
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