🤯 Why did JavaScript change my number? let a = 9999999999999999; console.log(a); // 10000000000000000 I didn’t change the value… But JavaScript did. 💡 Reason? JavaScript stores numbers as 64-bit floating point (IEEE 754) Because of this, it can only safely represent numbers up to: 👉 2^53 - 1 Beyond that → precision is lost ❌ So: 👉 9999999999999999 becomes 10000000000000000 ✅ Fix: Use BigInt let a = 9999999999999999n; 💭 Did you know this before? #JavaScript #Coding #Developers #WebDevelopment #Programming
Why JavaScript Changed My Number
More Relevant Posts
-
Just realized something interesting about JavaScripts memory optimisation behaviour with primitives while digging into runtime behavior 👇 Values like true, false, undefined, null, and even common string literals (like "") aren’t recreated every time you declare them. JS engines (like V8) treat these as shared, immutable values: • They exist only once internally • Variables just hold references to them So when you write: let a = true; let b = true; You’re not creating two true values — both just point to the same underlying value. Same idea applies to: • false • undefined • null • frequently used string literals 👉 Small detail, but shows how much memory optimization happens under the hood, a neat reminder that JavaScript does more for performance than we often think. #JavaScript #V8 #Performance #Programming #Backend
To view or add a comment, sign in
-
DOM Manipulation Challenge: Are you doing it WRONG? Let's test your JavaScript logic! 🧠 Look at the code in the image. We added click listeners to 1,000 items. Then, we added a brand new item to the list. Question: When you click that NEW item, what happens in the console? A) "Item clicked!" B) Nothing at all C) Error If you guessed B, you're right! This is why "Event Delegation" is a senior-level skill every developer needs to master. It saves memory and handles new items automatically. 💻✨ Tell me your answer in the comments! 👇 Hashtags: #JavaScript #CodingQuiz #WebDev #100DaysOfCode #LearnToCode #CodeWithSarir #FrontendDevelopment #ProgrammingTips #JSLogic #codinglife #programmer
To view or add a comment, sign in
-
-
Most JavaScript developers have seen this but never understood why. Type 0.1 + 0.2 in your console. You expect 0.3. You get 0.30000000000000004. This is not a JavaScript bug. It is IEEE 754 — the standard for how ALL computers store numbers in binary. 0.1 and 0.2 cannot be represented exactly in binary, just like 1/3 cannot be represented exactly in decimal. The tiny rounding errors accumulate. This silently breaks: → Currency calculations → Percentage comparisons → Any equality check with decimals The fix: → Use .toFixed() for display → Store currency as integers (cents) Were you aware of this? 1️⃣ Yes / 2️⃣ No #JavaScript #WebDev #Coding #SoftwareEngineering #Frontend
To view or add a comment, sign in
-
-
Instead of creating separate state for every input… You can manage all inputs using one state object. 👉 Use one state → store all form fields 👉 Use name attribute → identify input 👉 Update dynamically using onChange 📌 Example fields: • name • email • password 📌 How it works: 1️⃣ Create one state object 2️⃣ Add name to inputs 3️⃣ Use one onChange handler 4️⃣ Update using [name]: value ⚡ This makes your form: ✔ Cleaner ✔ Scalable ✔ Easy to manage Master this to build real-world forms in React. Follow TFSC for practical frontend learning. #reactjs #reactforms #frontenddevelopment #javascript #webdevelopment #coding #learnreact #programming #tfsc
To view or add a comment, sign in
-
Just published a deep dive into how V8 handles arrays under the hood 🚀 Key takeaway: not all arrays are equal. Packed arrays (SMI/Double) and TypedArrays are highly optimized, while holey and mixed arrays introduce hidden performance costs due to extra checks and de-optimizations. If you're writing performance-critical JavaScript, these low-level details *matter more than you think*. I’ve also included a benchmark to see the differences yourself 👇 https://lnkd.in/gsxGFNZv #JavaScript #V8 #Performance #NodeJS #Programming
To view or add a comment, sign in
-
-
💡 JavaScript Challenge function sum(a, b) { return a + b; } function sumCurried(a) { return function(b) { return a + b; }; } console.log(sum(5, 4)); console.log(sumCurried(5)(4)); ❓ What’s the output? Two different approaches… one result. But here’s the real question 👇 Are you more curious about the answer… or how both paths lead there? 👇 Drop your answer below! 🔗 Follow me for more insights on coding, creativity & branding. #JavaScript #WebDevelopment #CodingChallenge #Curiosity #Programming #Developers #LearnToCode
To view or add a comment, sign in
-
-
JavaScript Logical Series – Day 1 👉 What will be the output? console.log(1 + "2" + "2"); console.log(1 + +"2" + "2"); console.log(1 + -"1" + "2"); console.log(+"1" + "1" + "2"); Output : 122 32 02 112 Explanation • "2" → string → concatenation happens • +"2" → converts string to number • -"1" → converts to number (-1) • Order of operations matters 🔥 Key Point JavaScript type coercion can change output unexpectedly. Always be careful with + operator. #JavaScript #NodeJS #WebDevelopment #Programming #CodingChallenge #FrontendDevelopment #SoftwareEngineering
To view or add a comment, sign in
-
-
Most JavaScript devs mess this up! Here's the actual rule: this is not about where the function is written. It's about how it's called. The 4 binding rules (in priority order): new binding — creates a new object Explicit binding — call/apply/bind force the context Implicit binding — object method calls Default binding — fallback (undefined or window) Where it breaks: Arrow functions inherit this from outer scope (lexical) Lost context when you extract a method from an object Rule of thumb: Arrow function? → lexical this Regular function? → check how it's called Confused? → use .bind() or arrow functions Stop guessing. Master the call-site. #JavaScript #WebDev #Programming
To view or add a comment, sign in
-
-
🚀 JavaScript Practice Update Today I practiced JavaScript Variables and Operators 💻 I focused on var, let, const and different operators like: ➕ Addition ➖ Subtraction ✖ Multiplication ➗ Division 🔁 Modulus Also solved some tricky questions 👇 ❓ 1. What will be the output? let a = 10; let b = "10"; console.log(a == b); console.log(a === b); ❓ 2. What will happen here? let x = 5; let y = x++; console.log(x, y); ❓ 3. Predict the output: console.log(2 + 3 + "5"); console.log("5" + 2 + 3); Still learning and improving step by step 📈 Consistency > Motivation 💯 #JavaScript #FrontendDevelopment #Coding #WebDevelopment #100DaysOfCode
To view or add a comment, sign in
-
⚠️ JavaScript trick you might be missing .sort() mutates your array. That means your original data gets changed in place — which can lead to unexpected bugs if you're not careful. ✅ Use .toSorted() instead It returns a new sorted array without modifying the original one. 💡 Why it matters: • No hidden side effects • Keeps your data predictable • Safer and cleaner code #JavaScript #WebDevelopment #Frontend #CleanCode #DevTips #Programming
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