JavaScript looks simple… until it doesn’t. Ever wondered why this code behaves differently in old vs modern JavaScript? if (08 == 8) { console.log("equal"); } else { console.log("unequal"); } 🥲Old JavaScript (pre-ES5) : Numbers starting with 0 were treated as octal (base-8). 08 → invalid octal Often interpreted as 0 since 8 is invalid octal number. Result: 0 == 8 // false So, Output: unequal 😄 Modern JavaScript (ES5+) Leading zero no longer means octal. 08 is treated as decimal 8 Result: 8 == 8 // true So, Output: equal 💡 The real lesson JavaScript evolved to remove confusing behavior Backward compatibility can hide dangerous bugs Always write clear, explicit code 👇Now use this 8 // decimal 0o10 // explicit octal (equals 8) Small details. Big bugs. That’s JavaScript for you. 😄 (Note - now you can't flex in front of non tech people that 018!=18 nor you can try this with Modern javascript 😑) #JavaScript #WebDevelopment #Programming #CodingTips #Developers #Tech #SoftwareEngineering LinkedIn -- Pralhad Saw
JavaScript's Hidden Pitfall: Leading Zero in Numbers
More Relevant Posts
-
🤔 𝗝𝗮𝘃𝗮𝗦𝗰𝗿𝗶𝗽𝘁 𝗤𝘂𝗶𝗿𝗸 𝗔𝗹𝗲𝗿𝘁: 𝗪𝗵𝘆 𝗱𝗼𝗲𝘀 𝘵𝘺𝘱𝘦𝘰𝘧 𝘯𝘶𝘭𝘭 === "𝘰𝘣𝘫𝘦𝘤𝘵"? Ever wondered why JavaScript thinks null is an object? It's not a feature—it's a bug from 1995 that we're stuck with forever! 𝗧𝗵𝗲 𝗢𝗿𝗶𝗴𝗶𝗻 𝗦𝘁𝗼𝗿𝘆: In JS v1, values had type tags. Objects got 000, and null (the NULL pointer) was all zeros. Boom—misidentified as an object. 𝗪𝗵𝘆 𝗖𝗮𝗻'𝘁 𝗪𝗲 𝗙𝗶𝘅 𝗜𝘁? 𝗦𝗶𝗺𝗽𝗹𝗲: backwards compatibility. In 2011, they tried fixing it by making 𝘵𝘺𝘱𝘦𝘰𝘧 𝘯𝘶𝘭𝘭 === "𝘯𝘶𝘭𝘭". 𝗥𝗲𝘀𝘂𝗹𝘁? Mass breakage across the web. 🔥 𝗠𝗶𝗹𝗹𝗶𝗼𝗻𝘀 𝗼𝗳 𝗰𝗼𝗱𝗲𝗯𝗮𝘀𝗲𝘀 𝗵𝗮𝘃𝗲: 𝘫𝘢𝘷𝘢𝘴𝘤𝘳𝘪𝘱𝘵𝘪𝘧 (𝘵𝘺𝘱𝘦𝘰𝘧 𝘷𝘢𝘭𝘶𝘦 === "𝘰𝘣𝘫𝘦𝘤𝘵" && 𝘷𝘢𝘭𝘶𝘦 !== 𝘯𝘶𝘭𝘭) { // 𝘩𝘢𝘯𝘥𝘭𝘦 𝘰𝘣𝘫𝘦𝘤𝘵𝘴 } Remove that && 𝘷𝘢𝘭𝘶𝘦 !== 𝘯𝘶𝘭𝘭 check, and chaos ensues. 𝗧𝗵𝗲 𝗟𝗲𝘀𝘀𝗼𝗻: Sometimes, the web's greatest strength (never breaking old sites) is also its biggest constraint. We live with legacy bugs because stability > theoretical perfection. What's your favorite JavaScript quirk? 👇 #JavaScript #WebDevelopment #Programming #DeveloperLife #TechTrivia #TechInnovation
To view or add a comment, sign in
-
-
I thought I understood this JavaScript concept… until I really did 👇 📌 Parameter Scope in JavaScript Function parameters are not special variables they are simply local variables scoped to the function. function greet(userName) { console.log(userName); } console.log(userName); // ❌ ReferenceError: userName is not defined Key Takeaway: userName exists only inside the function's execution context. But here’s the interesting part 👀 Parameters also follow lexical scope, which means inner functions can access them via closures: function outer(x) { function inner() { console.log(x); // ✅ Accesses 'x' from the outer scope } inner(); } And a subtle gotcha most beginners miss ⤵️ Default parameters are evaluated in their own scope at the moment the function is called, strictly before the function body begins to run. Understanding scope like this changed how I read and debug JavaScript code. Small concepts. Big clarity. 🚀 #JavaScript #WebDevelopment #LearningInPublic #Frontend #CodingTips #Scope
To view or add a comment, sign in
-
⚡ JavaScript Event Loop — The Concept That Makes JS Feel “Fast.” Ever wondered how JavaScript handles multiple tasks even though it’s single-threaded? Here are the key things to understand: 🧩 Call Stack Runs your code line by line (one task at a time). 🌐 Web APIs (Browser) Handles slow tasks like setTimeout, fetch, DOM events, etc. 📥 Callback Queue (Task Queue) Stores callbacks waiting to run after the stack is empty. ⚡ Job Queue (Microtask Queue) Promises go here — and it runs before the callback queue ✅ 🔁 Event Loop Continuously checks if the call stack is empty, then pushes queued tasks back to execution. Understanding this helps you: ✅ predict async output order ✅ fix “why is this logging first?” confusion ✅ write better Promise/async-await code ✅ understand sequence vs parallel vs race I wrote a beginner-friendly breakdown with examples. Link in the comments 👇 #JavaScript #WebDevelopment #Frontend #Programming #LearnJavaScript #SoftwareEngineering #Async #EventLoop
To view or add a comment, sign in
-
-
The only JavaScript function that comes with a "Pause" button. ⏯️ In JavaScript, the golden rule of functions is usually "Run-to-Completion." Once a function starts, it doesn't stop until it returns or finishes. 𝐄𝐧𝐭𝐞𝐫 𝐭𝐡𝐞 𝐆𝐞𝐧𝐞𝐫𝐚𝐭𝐨𝐫 𝐅𝐮𝐧𝐜𝐭𝐢𝐨𝐧. 🤯 It completely breaks the rule. It is a special type of function that can be paused in the middle of execution and resumed later from exactly where it left off. 𝐓𝐡𝐞 𝐌𝐚𝐠𝐢𝐜 𝐒𝐲𝐧𝐭𝐚𝐱: 1️⃣ `function*`: The asterisk tells JS this isn't a normal function. 2️⃣ `yield`: This keyword acts like a pause button. It spits out a value and freezes the function's state. 3️⃣ `.next()`: This is the play button. Call it to resume the function until it hits the next `yield`. 𝐖𝐡𝐲 𝐢𝐬 𝐭𝐡𝐢𝐬 𝐮𝐬𝐞𝐟𝐮𝐥? (𝐋𝐚𝐳𝐲 𝐄𝐯𝐚𝐥𝐮𝐚𝐭𝐢𝐨𝐧) Generators allow for 𝐋𝐚𝐳𝐲 𝐄𝐯𝐚𝐥𝐮𝐚𝐭𝐢𝐨𝐧. You don't have to calculate a list of 1 million items at once (crashing your memory). You can generate them one by one, only when you actually need them. It’s perfect for infinite streams, ID generators, or defining complex state machines. Check out the syntax breakdown below! 👇 Have you used Generators in production (maybe with Redux Saga)? #JavaScript #WebDevelopment #CodingPatterns #AdvancedJS #SoftwareEngineering #Frontend
To view or add a comment, sign in
-
-
💠 JavaScript slice() Method — Explained Simply The slice() method is used to extract a portion of an array or string without modifying the original data. It returns a new array or string, making it a non-mutating and safe operation. 🔍 Key Characteristics 🔸 Does not mutate the original array or string 🔸 Supports negative indexes 🔸 Commonly used for copying arrays, pagination, and sub-list creation 👉 Real-World Use Case 🔹 In React applications, slice() is often used for: 🔹 Pagination 🔹 Displaying partial lists 🔹 Maintaining immutability during state updates 💡 Why it matters 🔹 In React and modern JavaScript, immutability is key. 🔹 slice() helps maintain clean, predictable state updates. #JavaScript #FrontendDevelopment #ReactJS #WebDevelopment #CodingTips #LearnJavaScript #Programming
To view or add a comment, sign in
-
-
While learning JavaScript, I noticed something that felt really strange at first. If you create a variable without using let, var, or const, JavaScript doesn’t throw an error. Instead… it silently creates a new variable What’s even more surprising is that this variable can be accessed outside the block where it was written. So how does this happen? When the JavaScript engine encounters a variable, it first checks the current block scope. If it doesn’t find it, it keeps going up through the parent scopes. If the variable is still not found, JavaScript creates it in the global scope, making it accessible everywhere. This behavior comes from the early philosophy of JavaScript. The language was designed to be forgiving and flexible, to help developers build web pages quickly without strict rules getting in the way. But this flexibility comes at a cost. Accidentally creating global variables can lead to: Data leaking between parts of the app Hard-to-track bugs Conflicts between scripts Once developers realized how dangerous this could be, Strict Mode was introduced: Js "use strict"; With strict mode enabled, JavaScript throws an error when you try to use an undeclared variable, preventing this silent leakage. This was a great reminder for me that JavaScript’s “weird” behaviors usually have historical reasons behind them — and understanding those reasons makes you a better developer, not just a user of the language. #JavaScript #JS #LearningJoureny #Web #SWE #coding
To view or add a comment, sign in
-
-
🧩 JavaScript – Functions A function is simply a block of code that you can reuse whenever you need it. In simple words: A function is a small machine that does one job when you call it. Example: *** function greet() { console.log("Hello!"); } greet(); greet(); *** Here: ● function greet() → we create the function ● greet() → we call the function Every time you call it, the same code runs again. Why functions are powerful: • They reduce repeated code • They make your program clean • They break big problems into small parts • They are easy to test and debug Think like this: Instead of writing the same logic again and again, you write it once inside a function and reuse it anywhere. Example: *** function add(a, b) { return a + b; } add(2, 3); // 5 add(10, 20); // 30 *** One function. Many uses. Functions are the building blocks of JavaScript. Mastering them makes you think like a real developer. #Day2 #JavaScript #Functions #Frontend #WebDevelopment #LearningInPublic #Developers #CareerGrowth
To view or add a comment, sign in
-
𝗪𝗵𝗲𝗻 𝗝𝗮𝘃𝗮𝗦𝗰𝗿𝗶𝗽𝘁 𝗗𝗲𝗰𝗶𝗱𝗲𝘀 𝗠𝗮𝘁𝗵 𝗜𝘀 𝗮 𝗦𝘂𝗴𝗴𝗲𝘀𝘁𝗶𝗼𝗻 2 + 0 = 20 6 + 6 = 66 𝗪𝗿𝗼𝗻𝗴? Not if you speak JavaScript. 𝗘𝘃𝗲𝗿𝘆 𝗝𝗦 𝗱𝗲𝘃’𝘀 𝗳𝗶𝗿𝘀𝘁 𝗿𝗲𝗮𝗰𝘁𝗶𝗼𝗻: “Hold on… what’s the type?” 👀 Because in JavaScript: "2" + 0 becomes "20" "6" + "6" becomes "66" The + operator multitasks Your assumptions don’t 🧠 JavaScript doesn’t guess intent. 𝗜𝘁 𝗳𝗼𝗹𝗹𝗼𝘄𝘀 𝗿𝘂𝗹𝗲𝘀: 𝗳𝗹𝗲𝘅𝗶𝗯𝗹𝗲, 𝗱𝗮𝗻𝗴𝗲𝗿𝗼𝘂𝘀 𝗿𝘂𝗹𝗲𝘀. 𝗪𝗵𝗮𝘁 𝗹𝗼𝗼𝗸𝘀 𝗹𝗶𝗸𝗲 𝗯𝗿𝗼𝗸𝗲𝗻 𝗺𝗮𝘁𝗵 𝗶𝘀 𝗮𝗰𝘁𝘂𝗮𝗹𝗹𝘆: 👉 implicit type coercion 👉 string concatenation 👉 logic doing exactly what you asked for 😅 𝗧𝗵𝗲 𝗿𝗲𝗮𝗹 𝗯𝘂𝗴 𝗶𝘀𝗻’𝘁 𝗝𝗮𝘃𝗮𝗦𝗰𝗿𝗶𝗽𝘁. It’s forgetting that inputs lie. 📌 𝗧𝗮𝗸𝗲𝗮𝘄𝗮𝘆 𝗳𝗼𝗿 𝗱𝗲𝘃𝗲𝗹𝗼𝗽𝗲𝗿𝘀: • Be explicit with types • Validate inputs early • Never assume + means addition JavaScript gives you freedom. And freedom, as usual, comes with consequences. 🤝 𝗘𝘃𝗲𝗿𝘆 𝗝𝗦 𝗱𝗲𝘃𝗲𝗹𝗼𝗽𝗲𝗿 𝗹𝗲𝗮𝗿𝗻𝘀 𝘁𝗵𝗶𝘀 𝘁𝗵𝗲 𝗵𝗮𝗿𝗱 𝘄𝗮𝘆 𝗼𝗻𝗰𝗲. #JavaScript #TypeCoercion #FrontendDevelopment #ProgrammingHumor #CodingTips
To view or add a comment, sign in
-
-
𝗪𝗵𝗲𝗻 𝗝𝗮𝘃𝗮𝗦𝗰𝗿𝗶𝗽𝘁 𝗗𝗲𝗰𝗶𝗱𝗲𝘀 𝗠𝗮𝘁𝗵 𝗜𝘀 𝗮 𝗦𝘂𝗴𝗴𝗲𝘀𝘁𝗶𝗼𝗻 2 + 0 = 20 6 + 6 = 66 𝗪𝗿𝗼𝗻𝗴? Not if you speak JavaScript. 𝗘𝘃𝗲𝗿𝘆 𝗝𝗦 𝗱𝗲𝘃’𝘀 𝗳𝗶𝗿𝘀𝘁 𝗿𝗲𝗮𝗰𝘁𝗶𝗼𝗻: “Hold on… what’s the type?” 👀 Because in JavaScript: "2" + 0 becomes "20" "6" + "6" becomes "66" The + operator multitasks Your assumptions don’t 🧠 JavaScript doesn’t guess intent. 𝗜𝘁 𝗳𝗼𝗹𝗹𝗼𝘄𝘀 𝗿𝘂𝗹𝗲𝘀: 𝗳𝗹𝗲𝘅𝗶𝗯𝗹𝗲, 𝗱𝗮𝗻𝗴𝗲𝗿𝗼𝘂𝘀 𝗿𝘂𝗹𝗲𝘀. 𝗪𝗵𝗮𝘁 𝗹𝗼𝗼𝗸𝘀 𝗹𝗶𝗸𝗲 𝗯𝗿𝗼𝗸𝗲𝗻 𝗺𝗮𝘁𝗵 𝗶𝘀 𝗮𝗰𝘁𝘂𝗮𝗹𝗹𝘆: 👉 implicit type coercion 👉 string concatenation 👉 logic doing exactly what you asked for 😅 𝗧𝗵𝗲 𝗿𝗲𝗮𝗹 𝗯𝘂𝗴 𝗶𝘀𝗻’𝘁 𝗝𝗮𝘃𝗮𝗦𝗰𝗿𝗶𝗽𝘁. It’s forgetting that inputs lie. 📌 𝗧𝗮𝗸𝗲𝗮𝘄𝗮𝘆 𝗳𝗼𝗿 𝗱𝗲𝘃𝗲𝗹𝗼𝗽𝗲𝗿𝘀: • Be explicit with types • Validate inputs early • Never assume + means addition JavaScript gives you freedom. And freedom, as usual, comes with consequences. 🤝 𝗘𝘃𝗲𝗿𝘆 𝗝𝗦 𝗱𝗲𝘃𝗲𝗹𝗼𝗽𝗲𝗿 𝗹𝗲𝗮𝗿𝗻𝘀 𝘁𝗵𝗶𝘀 𝘁𝗵𝗲 𝗵𝗮𝗿𝗱 𝘄𝗮𝘆 𝗼𝗻𝗰𝗲. #JavaScript #TypeCoercion #FrontendDevelopment #ProgrammingHumor #CodingTips
To view or add a comment, sign in
-
-
7 Type of Loops in JavaScript 🔄🤔 Most developers stick to for or forEach, but JavaScript offers 7 different ways to iterate over data. Choosing the wrong one can lead to messy code or performance bottlenecks. The Loop Cheat Sheet: ✅ for loop: The classic, manual control loop. ✅ while loop: Runs as long as a condition is true. ✅ do...while: Guarantees the code runs at least once. ✅ for...in: Best for iterating over object keys. ✅ for...of: The modern standard for arrays and strings.. ✅ forEach(): Cleaner syntax for arrays, but no break or continue. ✅ map(): Transformations that return a new array. Swipe left to master them all! ⬅️ 💡 Found this helpful? * Follow for premium web development insights. 🚀 * Repost to help your network stay updated. 🔁 * Comment which loop is your personal favorite! 👇 #javascript #webdevelopment #coding #frontend #loops #programming #codewithalamin #webdeveloper #js #codingtips
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
Lion be like - Jungle mein d Dhahadne se ghar nhi chlta mitra...