Day 15 of me reading random and basic but important coding facts...... Today I read about JS Numbers, and I found some really cool details that often go unnoticed..... Reading large numbers is hard. JS lets us use underscores as separators or e notation. The engine treats them all exactly the same by ignoring underscores...... const billion1 = 1000000000; const billion2 = 1_000_000_000; const billion3 = 1e9; ......1*10^9 console.log(billion1 === billion2); // true console.log(billion1 === billion3); // true Number() is strict (it wants a pure number means can't convert if there is any other thing present except numeral digit ), but parseInt() is forgiving it reads until it hits a non-number. const width = "250px"; console.log(Number(width)); // NaN console.log(parseInt(width)); // 250 We can write numbers in different bases directly in our code using prefixes. // All of these print 255 console.log(0xff); // Hex (0x prefix) console.log(0b11111111); // Binary (0b prefix) console.log(0o377); // Octal (0o prefix) Keep Learning!!!!!! #JavaScript #Coding #WebDevelopment #SoftwareEngineering #FrontEndDev
JavaScript Number Facts and Tricks
More Relevant Posts
-
🚀 JavaScript Tip: Find the Most Occurring Letter in a String – Optimized & Efficient function mostOccurringLetter(str) { const freq = {}; let maxCount = 0; let result = ''; for (let char of str) { freq[char] = (freq[char] || 0) + 1; if (freq[char] > maxCount) { maxCount = freq[char]; result = char; } } return result; } console.log(mostOccurringLetter('banana')); // Output: 'a' 🔑 Key Idea Frequency Counting: Count each letter’s occurrences using an object and track the maximum frequency dynamically — avoids multiple loops and keeps it single-pass. #JavaScript #WebDevelopment #CodingTips #Algorithm #DataStructures #Programming #CleanCode #DeveloperLife #TechTips #CodeOptimization #100DaysOfCode #CodingInterview
To view or add a comment, sign in
-
I had a small but powerful “aha” moment while solving a Codewars problem. I realized the difference between reversing a string vs reversing an array of elements, and how it affects performance. Example: // Reversing a string (slow for huge strings) let str = "ab".repeat(1e6); str.split("").reverse().join(""); // Reversing an array of strings (fast) let arr = ["a".repeat(1e6), "b".repeat(1e6)]; arr.reverse(); // just moves references, no copying characters String reverse: touches every character → slow Array reverse: moves references → fast I understood this while solving a Codewars example, and it helped me understand performance and memory in JavaScript better. #JavaScript #Codewars #Performance
To view or add a comment, sign in
-
🤯 JavaScript sort() — When Numbers Pretend to Be Strings (V8 Deep Dive) Ever tried this in JavaScript? [11, 3, 2, 45].sort() O/P: [11, 2, 3, 45] At first glance, it looks like JavaScript forgot how numbers work 😅 But nope — V8 is just following the rules. 🧠 What V8 actually does under the hood 1️⃣ Numbers are converted to strings 11 → "11" 2 → "2" 2️⃣ Strings are compared lexicographically (UTF-16 code units, left → right) 👉 '1' → 49 👉 '2' → 50 Since 49 < 50, "11" comes before "2 V8 stops comparison at the first mismatch — no second character needed 👀 🎭 Moral of the story JavaScript isn’t bad at math. It’s just really good at following specs 📜 By default: Array.prototype.sort() → string comparison Numeric intent? → You must say it explicitly 🏎️ V8 Engine Fun Fact ☑️ V8 uses TimSort (hybrid of merge + insertion sort) ☑️ Stable ☑️ Optimized for real-world data ☑️ But the comparison logic is still yours to define 😉 #JavaScript #V8Engine #WebPerformance #FullStackDeveloper #DeepDive #JSInternals #InterviewPrep #NodeJS #sort #numbersort #v8 #js
To view or add a comment, sign in
-
🤯 JavaScript sort() — When Numbers Pretend to Be Strings (V8 Deep Dive) Ever tried this in JavaScript? [11, 3, 2, 45].sort() O/P: [11, 2, 3, 45] At first glance, it looks like JavaScript forgot how numbers work 😅 But nope — V8 is just following the rules. 🧠 What V8 actually does under the hood 1️⃣ Numbers are converted to strings 11 → "11" 2 → "2" 2️⃣ Strings are compared lexicographically (UTF-16 code units, left → right) 👉 '1' → 49 👉 '2' → 50 Since 49 < 50, "11" comes before "2 V8 stops comparison at the first mismatch — no second character needed 👀 🎭 Moral of the story JavaScript isn’t bad at math. It’s just really good at following specs 📜 By default: Array.prototype.sort() → string comparison Numeric intent? → You must say it explicitly 🏎️ V8 Engine Fun Fact ☑️ V8 uses TimSort (hybrid of merge + insertion sort) ☑️ Stable ☑️ Optimized for real-world data ☑️ But the comparison logic is still yours to define 😉 hashtag #JavaScript #V8Engine #WebPerformance #FullStackDeveloper #DeepDive #JSInternals #InterviewPrep #NodeJS #sort #numbersort #v8 #js #NodeJS #JavaScript #WebSockets #RealTime #WebDevelopment #BackendDevelopment #Developers #Programming #TechCommunity #SoftwareEngineering
To view or add a comment, sign in
-
Day 4 of #100DaysOfCode: Array Logic & The Magic of Truthy/Falsy in JS ⚡ Today was about mastering the fundamentals that make JavaScript unique. I split my time between solving algorithmic problems and digging deep into JS engine mechanics. 1️⃣ Data Structures & Algorithms: I tackled the "Concatenation of Array" problem (LeetCode 1929). The goal was to create an array of length 2n by concatenating two nums arrays. Key takeaway: It’s a great exercise in understanding array indexing and memory allocation. It’s simple on the surface, but efficient array manipulation is core to everything. 2️⃣ Web Development Concepts: I dove into Truthy & Falsy values. Coming from other languages, JS handling of conditionals is fascinating. I learned that 0, "", null, undefined, and NaN are the only falsy values. Everything else—including empty arrays [] and objects {}—is truthy. #JavaScript #DSA #WebDevelopment #MERNStack #CodingJourney #100DaysOfChallenge
To view or add a comment, sign in
-
Day 17 of me reading random and basic but important coding facts.... Today I read about Arrays in JS and turns out, they aren't just simple lists..... Push/Pop vs. Shift/Unshift Push /Pop is very fast as it just adds/removes from the end.... while Shift/Unshift is very slow.....becoz when we remove the first element, the engine has to physically move every single other element to the left to fix the indices....... and another very very interesting fact is that the length property isn't read-only.............. If we set arr.length = 0, it instantly clears the array. If we manually decrease the length (e.g., arr.length = 2), it truncates the data from the end.....and there is no coming back....... So, use them wisely..... Keep Learning!!!!! #javascript #coding #webdevelopment #learning #frontendDev
To view or add a comment, sign in
-
I had a function using Array.map(). The output was always undefined. At first I assumed: “map automatically returns transformed values.” ❌ Wrong assumption. Root cause: I forgot to return a value inside the callback. map does NOT mutate or guess logic. No return = undefined. Fix: Explicitly return the value. Small mistake, big logic lesson: JavaScript array methods are declarative, not magical. // ❌ Bug const nums = [1, 2, 3]; const result = nums.map(n => { n * 2; }); // ✅ Fix const fixed = nums.map(n => { return n * 2; }); #JavaScript #FrontendDevelopment #ProgrammingBasics #CleanCode #WebDevelopment
To view or add a comment, sign in
-
'Pick' and 'Omit' are great for objects. But what about union types? If you’ve used 'Pick' and 'Omit' before, you already understand one important idea in TypeScript - 'We can derive new types from existing ones instead of rewriting them.' But 'Pick' and 'Omit' only work on object shapes. What happens when you’re working with union types instead? That’s exactly where 'Extract' and 'Exclude' come in. Think of them as filters for union types. While 'Pick' and 'Omit' operate on keys of objects, 'Extract' and 'Exclude' operate on members of union types. Conceptually, 'Extract' keeps what matches & 'Exclude' removes what matches. So, when you write 'Extract<A, B>', it means 'From union A, keep only the members that are assignable to B.' Similarly, when you write 'Exclude<A,B>', it means 'From union A, remove anything that is assignable to B.' These utility types shine when your codebase grows. They help you avoid duplicating unions, and keep types in sync automatically. If the original union evolves, your derived types evolve with it. No manual updates needed. #TypeScript #JavaScript #WebDevelopment #Programming #SoftwareEngineering
To view or add a comment, sign in
-
-
Today I explored how JavaScript code actually runs inside the V8 engine. When we give code to V8, the first stage is parsing. This starts with lexical analysis (tokenization), where the code is broken into small pieces called tokens. For example, in var a = 10, var, a, =, and 10 are all individual tokens. V8 reads the code token by token. Next comes syntax analysis, where these tokens are converted into an Abstract Syntax Tree (AST). The AST represents the structure and meaning of the code in a way the engine can understand. This AST is then passed to the Ignition interpreter, which converts it into bytecode. The bytecode is what actually gets executed at first. If V8 notices that some parts of the code—like a function—are used frequently, it tries to optimize them. These “hot” parts are sent to the TurboFan compiler, which turns the bytecode into highly optimized machine code for faster execution. This whole process is called Just-In-Time (JIT) compilation. Sometimes optimization fails. For example, if a function expects numbers but suddenly receives a string, V8 can no longer use the optimized machine code. This is called deoptimization, and the engine falls back to the Ignition interpreter and bytecode again. I also learned the basic difference between interpreted and compiled languages: Interpreters execute code line by line and start fast. Compilers first convert the entire high-level code into machine code, which takes more time initially but runs much faster afterward. This deep dive really helped me understand what’s happening behind the scenes when JavaScript runs. #JavaScript #NodeJS #V8Engine #WebDevelopment #SoftwareEngineering #Programming #Developers
To view or add a comment, sign in
-
Stop writing finally blocks. JavaScript 2026 has a better way. We’ve all been there: a production crash because a file handle wasn't closed or a database connection leaked. Historically, we relied on verbose try...catch...finally blocks to manage this. But the upcoming ECMAScript update is changing the game with Explicit Resource Management. The new using keyword allows you to bind resources to a block scope. When the block ends, the resource cleans itself up. Automatically. I just published a detailed guide on Medium covering: 🔹 The new using syntax (vs const) 🔹 How to implement Symbol.dispose 🔹 Handling async cleanup with await using 🔹 Why this creates a "pit of success" for developers #SoftwareEngineering #JavaScript #CleanCode #WebDevelopment #ES2026 Read the full breakdown here:
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