JavaScript math can be pretty wild. So, you've probably stumbled upon those tutorials that claim JavaScript math is, well, weird - and they're not entirely wrong. I mean, have you ever tried adding 0. and 0.2 in your console? It's like, what's going on? The result is this tiny, seemingly insignificant number: 0.00000004. Yeah, it's a real head-scratcher. It's simple. JavaScript stores numbers as floating-point values - that's just how it works. It uses the IEEE 754 floating-point representation, which is a system that has a fixed number of bits to store values. Now, here's the thing: some decimal values are infinitely repeating and non-terminating in binary - like , for instance. In binary, is represented as.000110011... and it just keeps going. Since this sequence repeats forever, it gets rounded off, so 0.1 isn't stored as exactly 0.1, but as a value slightly above it. Same thing with . So, when you add 0.1 and 0.2, you don't get exactly 0.3. It's not just JavaScript, though - other languages like Python, Java, and C++ have the same issue. They all use floating-point representation, but they often round values when printing them, which can make the problem less noticeable. JavaScript, on the other hand, shows you the raw result, which can make it seem like its math is weird, but really, it's just being honest. It's all about perspective. And, honestly, it's not that big of a deal - you just need to understand how it works. It's like trying to explain a complex concept, like a mathematical equation, in a simple way - sometimes you need to use analogies or metaphors to get the point across. Anyway, that's JavaScript math in a nutshell. Source: https://lnkd.in/gqWasR3b #JavaScript #Math #Programming
JavaScript Math: Understanding Floating-Point Representation
More Relevant Posts
-
JavaScript math can be pretty quirky. It's all about how numbers are stored, you see. So, here's the thing: JavaScript only has one numeric type - it's just called Number. And the kicker is, all numbers are stored as floating-point values. That's where things get interesting. Decimal values can be infinitely repeating in binary, which means they can't always be represented exactly. It's like trying to describe a color - you can get close, but it's hard to nail it down perfectly. For instance, in binary is 0.0001100110011001… with "0011" repeating forever. That's a mouthful, right? So, isn't stored exactly as , but a tiny bit above it. Same thing with . It's not a huge difference, but it's there. It adds up. So, when you do + 0.2, you don't get exactly 0.3, but something like 0.00000004. It's a tiny discrepancy, but it can make a big difference in certain calculations. Now, you might be thinking, "Is this just a JavaScript thing?" But no, it's not unique to JavaScript. Python, Java, C++, and C# all have the same issue. The difference is, most languages will format those floating-point numbers when displaying them, rounding the value to make it more readable. JavaScript, on the other hand, shows you the raw result - warts and all. It's like looking at a math problem through a microscope - you see all the tiny imperfections. But hey, at least you know what's going on, right? So, the next time you're working with JavaScript math and things don't quite add up, just remember: it's not you, it's the numbers. Source: https://lnkd.in/gqWasR3b #JavaScript #Math #Programming
To view or add a comment, sign in
-
Day-75 📘 Python Full Stack Journey – JavaScript String Methods Today I continued learning JavaScript and focused on one of the most commonly used areas — String methods. These methods are extremely useful for text processing, validation, and UI logic. ✍️💻 🎯 What I learned today: 🔹 length — to find the length of a string 🔹 replace() and replaceAll() — to modify text content 🔹 split() — to break strings into arrays 🔹 indexOf() — to find the position of a substring 🔹 slice() — to extract parts of a string 🔹 trim() — to remove extra spaces 🔹 startsWith() and endsWith() — to check string boundaries 🔹 toUpperCase() and toLowerCase() — to change letter cases 🔹 includes() — to check if a substring exists 🔹 search() — to search using patterns Practicing these methods helped me understand how JavaScript handles text and how powerful string manipulation can be in real-world applications like form validation and data handling. Excited to keep learning and building dynamic web features! 🚀 #JavaScript #PythonFullStack #WebDevelopment #Frontend #CodingJourney #LearningToCode #Upskilling #TechSkills #ContinuousLearning
To view or add a comment, sign in
-
-
🚀 Day 10: of Learning in Public: JavaScript Edition. 💻✨ --String Manipulation -Part2 in JavaScript 🧵-- Here's what I learned: ✅ substring() - Works only with positive indices Example: "Piyush Saxena".substring(7, 9) → "Sa" ✅ slice() - The more powerful cousin that supports negative indices Example: "Piyush Saxena".slice(-3, -1) → "en" Extract from end: "Piyush Saxena".slice(-3) → "ena" The Edge Case That Broke My Brain: When I tried slice(-3, 0), it returned an empty string! Spent 15 minutes debugging this. Why? Because slice() always extracts left-to-right. With negative start (-3) and zero end (0), there's nothing to extract since the start comes "after" the end in extraction order. Key takeaway: When using negative indices, stick with negative for both parameters, or skip the end index entirely. ✅ split() - My new favorite for parsing strings! Space delimiter: "My name is Piyush Saxena".split(" ") → ["My", "name", "is", "Piyush", "Saxena"] (5 elements) Comma delimiter: "My name is Piyush Saxena, I am learning JS".split(",") → 2 elements No more manual character iteration for word counting! JavaScript keeps surprising me with these little details. Every day is a new learning adventure! #JavaScript #CodingJourney #LearningInPublic #TechCommunity #NodeJS #TestAutomation #JavaVsJS #SDET
To view or add a comment, sign in
-
-
Day-80 📘 Python Full Stack Journey – JavaScript Logic & Conditions Today I focused on decision-making and logic in JavaScript — essential concepts for building interactive and dynamic applications. 🎯 What I learned today: 🔍 Comparison Operators ==, === !=, !== >, <, >=, <= Understanding the difference between loose and strict comparison was especially important. 🔗 Logical Operators && (AND) || (OR) ! (NOT) Used for combining and controlling conditions. ❓ Conditional (Ternary) Operator A concise way to write simple if-else conditions. 🧭 Conditional Statements Making decisions in code using if, else if, and else. 🧑💻 User Interaction prompt() — taking input from the user alert() — displaying messages to the user These concepts showed me how JavaScript brings logic and interactivity together on the web. Excited to keep building smarter, user-driven applications! 🚀 #JavaScript #PythonFullStack #WebDevelopment #Frontend #CodingJourney #LearningToCode #Upskilling #TechSkills #ContinuousLearning
To view or add a comment, sign in
-
-
This is a great update to share! The introduction of the if() function is a significant milestone because it brings CSS closer to the "logic" we usually see in languages like JavaScript or Python, without losing its declarative nature. To make your post more engaging and clear for your audience, I’ve restructured it to highlight the "Why it matters" and provided a clear code comparison. 🚀 Is CSS Becoming a Programming Language? Not exactly—but it’s getting a major "brain" upgrade! Traditionally, logic in CSS (like media queries) requires jumping between different blocks of code. It works, but it can feel fragmented and repetitive. That’s about to change with the new CSS if() function. 💡 What’s changing? The if() function allows you to write inline conditional logic. Instead of writing an entire media query block to change one value, you can handle it directly inside the property declaration. #programing #css #coding #Csslanguage
To view or add a comment, sign in
-
-
100 Days of Learning Challenge – Day 24 / 100 Today, I focused on JavaScript string methods and practiced how to manipulate and transform text efficiently. ------------------------------- Topics covered: 1. String methods trim() 2. Strings are immutable in JavaScript 3. toUpperCase() and toLowerCase() 4. Methods with arguments (indexOf) 5. Method chaining 6. slice() 7. replace() and repeat() 8. Practice questions ----------------------------------------------- String methods are small tools, but mastering them makes real-world tasks like validation, formatting, and data cleaning much easier. #100DaysOfLearning #JavaScript #WebDevelopment #Programming #Frontend #CodingPractice #DailyLearning
To view or add a comment, sign in
-
I built a web browser (kind of) from scratch. And yes, it runs on Python. We stare at web browsers all day, but rarely stop to think about the sheer engineering magic happening behind that URL bar. How does a string of HTML turn into pixels? How does display: flex actually know where to put things? I decided to stop wondering and start building. I’ve been deep in the trenches building a custom browser engine from the ground up in Python. No Chromium wrapper. No WebKit. Just raw code handling everything from the network layer to the final pixel paint. But here’s the twist: It doesn’t use JavaScript. I wanted to explore a "what if" scenario: What if Python was the first-class language of the web? In this prototype, instead of <script> , you write <script type="text/python"> You manipulate the DOM, handle click events, and animate styles, all using native Python code running directly in the browser. Some of the engineering wins: ✅ Custom Layout Engine: I had to write my own Flexbox and Grid implementation. (Respect to browser engineers, like always for me math is hard). ✅ Time Travel Debugging: Since the engine tracks every state change, I built a slider that lets you "rewind" your user session to see exactly how the UI looked seconds ago. ✅ Hot Reload: Because waiting for refreshes is not cool (sometimes it is). It’s not going to replace Chrome tomorrow. It’s strictly a research prototype. But seeing my own engine parse HTML and execute Python to render a live, interactive page? That’s a feeling hard to beat. It reminded me why I love engineering in the first place, taking the "magic" apart until it’s just logic. Repo: https://lnkd.in/gXzBgcNn #Python #SoftwareEngineering #WebDevelopment #BrowserEngine #OpenSource #Coding
To view or add a comment, sign in
-
Day-76 📘 Python Full Stack Journey – JavaScript String & Number Methods Today I continued strengthening my JavaScript fundamentals by learning how to work with strings and numbers more effectively. 🎯 What I learned today: ✍️ String Method 🔹 concat() — used to join multiple strings into a single string in a clean and readable way. 🔢 Number Methods 🔹 toFixed() — formats numbers by fixing the number of decimal places. 🔹 toPrecision() — formats numbers to a specified total number of digits. These methods are especially useful for data formatting, calculations, and displaying user-friendly values in real-world applications. Step by step, JavaScript is becoming clearer and more powerful. Looking forward to learning more! 🚀 #JavaScript #PythonFullStack #WebDevelopment #Frontend #CodingJourney #LearningToCode #Upskilling #TechSkills #ContinuousLearning
To view or add a comment, sign in
-
-
Day-79 📘 Python Full Stack Journey – JavaScript Objects, Maps & Operators Today I went deeper into JavaScript fundamentals, focusing on how data is structured, manipulated, and operated on within programs. 🎯 What I learned today: 🧱 JavaScript Objects How to change values in an object How to add new key–value pairs How to delete existing key–value pairs How to extract keys and values, which are stored as arrays 🗺️ JavaScript Map Defined using the new keyword with the Map() constructor Maps are ordered and mutable 🔧 Map Methods set() — add or update values get() — retrieve values has() — check existence delete() — remove entries ➕ JavaScript Operators Arithmetic Operators: +, -, *, /, **, %, ++, -- Assignment Operators: +=, -=, *=, /=, **=, %= These concepts are helping me better understand how JavaScript handles data and logic behind the scenes. Step by step, building a strong foundation for dynamic web development! 🚀 #JavaScript #PythonFullStack #WebDevelopment #Frontend #CodingJourney #LearningToCode #Upskilling #TechSkills #ContinuousLearning
To view or add a comment, sign in
-
-
Turning concepts into working code is the best way to learn. So I built a frontend web application using HTML, CSS, and JavaScript, along with a dummy Python backend server to simulate real backend behavior. What I learned from this project: - DOM manipulation and event handling - Structuring frontend code - How frontend communicates with backend - Handling basic requests using Python This project helped me understand how individual technologies come together to form a complete web application. I’m planning to extend this further using real APIs and databases. I’d really appreciate feedback and suggestions from the community. Tech Stack: HTML | CSS | JavaScript | Python #WebDevelopment #FrontendDeveloper #JavaScriptProjects #PythonLearning #BTechStudent #LearningByBuilding
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