JavaScript’s type coercion, truthy/falsy values, and implicit conversions can be twisted into something readable. Here's some code: (![] + [])[+[]] + ([] + {})[+!![] + [+!![]]] + ([] + {})[+!![] + [+!![]]] + (![] + [])[!+[] + !![]] + (+{} + {})[+!![] + [+[]]] + (![] + [])[+[]] + ([][[]] + [])[+[]] + ([][[]] + [])[+!![]] + (+{} + {})[+!![] + [+[]]] + ([][[]] + [])[+!![]] + ([] + {})[+!![]] +(!![] + [])[+[]] + (+{} + {})[+!![] + [+[]]] + (![] + [])[+[]] + ([] + {})[+!![] + [+!![]]] + (![] + [])[+!![]] + (!![] + [])[+!![]]; JavaScript is as quirky as it is powerful. #javascript #programming #software
JavaScript's quirky type coercion and truthy/falsy values
More Relevant Posts
-
Why You Should Avoid Using new Number(), new String(), and new Boolean() in JavaScript In JavaScript, there is an important distinction between primitive values and object wrappers. Consider the following example: let a = 3; // primitive number let b = new Number(3); // Number object console.log(a == b); // true (type coercion) console.log(a === b); // false (different types) This inconsistency occurs because new Number(), new String(), and new Boolean() create objects, not primitive values. Although they appear similar, they can cause subtle and hard-to-detect bugs in equality checks and logical comparisons. Common Issues Confusing equality checks (== vs ===) Unintended behavior in conditionals or truthy/falsey evaluations Inconsistent data handling across the codebase Recommended Best Practices Always use literals or function calls for primitive values: // Correct usage let x = 3; let y = "Hello"; let z = true; // Safe conversions Number("3"); // → 3 (primitive) String(123); // → "123" Boolean(0); // → false Use constructors like Date, Array, Object, and Function only when you intend to create objects. For Working with Dates Instead of relying solely on the Date object, consider modern and reliable alternatives: Intl.DateTimeFormat for formatting Temporal API (in modern JavaScript runtimes) for date and time arithmetic Key Takeaway If you encounter new Number(), new String(), or new Boolean() in your codebase, it is often a sign of a potential bug. Use literals for primitives, and reserve constructors for actual objects. #JavaScript #WebDevelopment #SoftwareEngineering #ProgrammingBestPractices #CleanCode #FrontendDevelopment #NodeJS #TypeScript #Developers
To view or add a comment, sign in
-
🌐 Introduction to JavaScript JavaScript is a lightweight, interactive scripting language that comes with many built-in methods. It plays a key role alongside HTML and CSS to make webpages dynamic and engaging. 🧩 Where JavaScript Is Used JavaScript is used in web development to: Add interactivity Handle user input Communicate with servers for dynamic content 💻 Example Script // Display an alert message window.alert("This is an alert message!"); // Print output to the console console.log("Hello from JavaScript!"); ⚙️ Features of JavaScript ✅ Easy to use ⚡ Fast response time 🔁 Flexible and powerful 🚀 JIT (Just-In-Time) compiler — works as both compiler and interpreter 🧠 Common Console Methods window.alert("Alert message"); console.log("Log message"); console.warn("Warning message"); console.info("Information message"); 📘 console: A built-in JS object giving access to the browser’s debugging console. 🧩 log(), warn(), info() are methods used to print messages or information. 🧱 Objects in JavaScript Objects are collections of properties and methods. Properties (fields): Store data like strings or numbers. Methods (functions): Perform actions. ⚠️ Common JavaScript Errors 1️⃣ Syntax Errors – mistakes in code structure 2️⃣ Reference Errors – using variables not defined 3️⃣ Type Errors – invalid operations on data types 🔡 JavaScript Variables – var, let, const Variables are used to store data values. There are three ways to declare them: var, let, and const 10000 Coders #Frontend #JavaScript #LearningNewThings #WebDevelopment #Coding #Programming
To view or add a comment, sign in
-
-
🔥 JavaScript: When “prototype” is NOT an object 👀 We all learn early — > “Every function in JavaScript has a prototype property that is an object.” But JavaScript loves exceptions 😏 Here are some surprising cases where prototype is not an object 👇 RegExp.prototype // → /(?:)/ Array.prototype // → [] Function.prototype // → ƒ () {} Number.prototype // → Number {} String.prototype // → String {} Boolean.prototype // → Boolean {} Symbol.prototype // → Symbol {} BigInt.prototype // → BigInt {} 💡 Notice something? Some of these are functions, arrays, or even regular expressions! That’s because their prototypes are actual instances of their types, not plain objects — so that all instances inherit their core methods directly. For example: Array.prototype.push === [].push // true ✅ RegExp.prototype.test === /abc/.test // true ✅ So next time you assume prototype is always {}, remember — JS is full of living examples 😉 --- 💬 Have you ever found a weird prototype behavior while debugging? Drop it in the comments — let’s break more JS myths together! ⚙️ #JavaScript #WebDevelopment #LearningEveryday #Frontend
To view or add a comment, sign in
-
Today's Topic: Promise Chaining in JavaScript In JavaScript, Promise chaining allows you to execute asynchronous tasks one after another, ensuring that each step waits for the previous one to finish. Instead of nesting callbacks (callback hell ), promises make your code cleaner and easier to maintain. Example: function step1() { return new Promise((resolve) => { setTimeout(() => { console.log("Step 1 completed ✅"); resolve(10); }, 1000); }); } function step2(value) { return new Promise((resolve) => { setTimeout(() => { console.log("Step 2 completed ✅"); resolve(value * 2); }, 1000); }); } function step3(value) { return new Promise((resolve) => { setTimeout(() => { console.log("Step 3 completed ✅"); resolve(value + 5); }, 1000); }); } // Promise Chaining step1() .then(result => step2(result)) .then(result => step3(result)) .then(finalResult => console.log("Final Result:", finalResult)) .catch(error => console.error("Error:", error)); ✅ Output (after 3 seconds): Step 1 completed ✅ Step 2 completed ✅ Step 3 completed ✅ Final Result: 25 Each .then() runs after the previous promise resolves — making async flow easy to read and manage. --- 🔖 #JavaScript #WebDevelopment #PromiseChain #AsyncProgramming #CodingTips #FrontendDevelopment #Developers #JSConcepts #CodeLearning #100DaysOfCode #WebDevCommunity
To view or add a comment, sign in
-
-
🧠 𝐉𝐚𝐯𝐚𝐒𝐜𝐫𝐢𝐩𝐭 𝐜𝐚𝐧 𝐛𝐞 𝐰𝐞𝐢𝐫𝐝. 𝐄𝐬𝐩𝐞𝐜𝐢𝐚𝐥𝐥𝐲 𝐰𝐡𝐞𝐧 𝐢𝐭 𝐜𝐨𝐦𝐞𝐬 𝐭𝐨 𝐭𝐲𝐩𝐞 𝐜𝐨𝐞𝐫𝐜𝐢𝐨𝐧. You write a simple expression. Expect a number. Get a string. Or worse NaN. Let’s walk through 5 real examples that trip up even experienced devs and what they actually return. 👇 🔹 1 + "2" + "2" Returns: "122" Why? 1 + "2" → "12" (number + string = string) "12" + "2" → "122" 🔹 1 + +"2" + "2" Returns: "32" Why? +"2" → 2 1 + 2 → 3 3 + "2" → "32" 🔹 1 + -"1" + "2" Returns: "02" Why? -"1" → -1 1 + (-1) → 0 0 + "2" → "02" 🔹 +"1" + "1" + "2" Returns: "112" Why? +"1" → 1 1 + "1" → "11" "11" + "2" → "112" 🔹 "A" - "B" + 2 Returns: NaN Why? "A" - "B" → NaN NaN + 2 → still NaN 💡 Key takeaways: - Unary + converts strings to numbers. - Mixing strings and numbers with + leads to string concatenation. - Non-numeric strings in math return NaN. - Always check your operand types before using +, -, or ==. If you’ve ever been confused by JavaScript’s quirks, you’re not alone. Type coercion is one of the most common sources of bugs in JS. Want more no fluff JavaScript breakdowns? Follow me here 👉 Sumit Mitra JavaScript can be weird. Especially when it comes to type coercion. #JavaScript #WebDevelopment #Frontend #CodingTips #TypeCoercion #JS #SoftwareEngineering
To view or add a comment, sign in
-
Demystifying the Prototype in JavaScript If there’s one concept that confuses most developers (even experienced ones), it’s the Prototype. Unlike traditional class-based languages, JavaScript uses prototypal inheritance — meaning objects can inherit directly from other objects. Every JS object has a hidden reference called its prototype, and this is what makes inheritance possible. 🔹 How It Works When you access a property like obj.prop1: 1️⃣ JS first checks if prop1 exists on the object itself. 2️⃣ If not, it looks at the object’s prototype. 3️⃣ If still not found, it continues up the prototype chain until it either finds it or reaches the end. So sometimes a property seems to belong to your object — but it actually lives further down the chain! Example const person = { firstname: "Default", lastname: "Default", getFullName() { return this.firstname + " " + this.lastname; } }; const john = Object.create(person); john.firstname = "John"; john.lastname = "Doe"; console.log(john.getFullName()); // "John Doe" Here’s what happens: JS looks for getFullName on john. Doesn’t find it → checks person (its prototype). Executes the method with this referring to john. Key Takeaways The prototype is just a hidden reference to another object. Properties are looked up the prototype chain until found. The this keyword refers to the object calling the method, not the prototype. Avoid using __proto__ directly — use Object.create() or modern class syntax. One-liner: The prototype chain is how JavaScript lets one object access properties and methods of another — simple, flexible, and core to the language. If you found this helpful, follow me for more bite-sized explanations on JavaScript, React, and modern web development #JavaScript #WebDevelopment #Frontend #React #TypeScript #Coding #LearningInPublic #SoftwareEngineering #TechEducation #WebDevCommunity
To view or add a comment, sign in
-
Most beginners write messy if-else logic — pros don’t. In JavaScript, mastering conditional statements means writing logic that’s not just functional, but readable and scalable. This post breaks down every major pattern: 1. if / else / else if 2. switch 3. ternary operator 4. logical & short-circuit operators 5. optional chaining and nullish coalescing real-world validation and role-based logic Want to level up your JavaScript readability game? Share the worst if-else chain you’ve ever written. https://lnkd.in/dVuD2ZWq #JavaScript #WebDevelopment #CodingTips #FrontendDev #ProgrammingBasics #LearnToCode #Nextjs #MERNStack
To view or add a comment, sign in
-
🚀 New Blog Alert! Ever changed a nested value in JavaScript and wondered why your original object also changed? 😅 That’s the hidden magic (and pain) behind shallow vs deep copy in JavaScript. In my latest Medium article, I’ve broken down: 🧠 How JavaScript handles memory (stack vs heap) 🔍 Why shallow copies share references ⚙️ How deep copy truly works under the hood 💡 Real-world examples using structuredClone(), Object.assign(), and lodash.cloneDeep() 👉 Read here: https://lnkd.in/d9VdByK6 #JavaScript #WebDevelopment #Coding #DeepCopy #ShallowCopy #Frontend #MERN #ShubhamDeveloper
To view or add a comment, sign in
-
💡 Ever changed a copy of an object… and accidentally changed the original too? If you’ve worked with JavaScript, you know this painful trap all too well! Let’s clarify the difference between shallow copy and deep copy, and see how modern JS handles it. 🔹 Shallow Copy A shallow copy duplicates only the top-level properties. Nested objects or arrays are still shared. const original = { name: "Alice", details: { age: 25 } }; const shallowCopy = { ...original }; shallowCopy.details.age = 30; console.log(original.details.age); // 30 → original object changed! ✅ Top-level copied. ⚠️ Nested objects still reference the same memory. 🔹 Deep Copy A deep copy duplicates everything, including nested objects, so changes don’t affect the original. 1️⃣ Using JSON.stringify() + JSON.parse() const original = { name: "Alice", details: { age: 25 } }; const deepCopy = JSON.parse(JSON.stringify(original)); deepCopy.details.age = 30; console.log(original.details.age); // 25 → safe! ⚠️ Limitation: Doesn’t handle Dates, Maps, Sets, functions, or circular references. 2️⃣ Using structuredClone() (Modern JS) const original = { name: "Alice", details: { age: 25 } }; const deepCopy = structuredClone(original); deepCopy.details.age = 30; console.log(original.details.age); // 25 → safe! ✅ Handles most types, including Date, Map, Set, etc. ⚠️ Available in modern browsers & Node.js v17+. #JS #JavaScript #WebDevelopment #DeepCopy #ShallowCopy #CodingTips #Programming
To view or add a comment, sign in
-
🚀 Day 30/50 – Function Currying in JavaScript Think of Function Currying like building a relationship. You don’t propose directly 😅 First comes the “Hi Hello 👋” phase → then friendship ☕ → and finally… the proposal ❤️ In JavaScript, instead of passing all arguments at once, Function Currying lets us pass them step by step, each step returning a new function until the final output is achieved. Here’s a simple code analogy from my video: function proposeTo(crush) { return function (timeSpent) { return function (gift) { return `Dear ${crush}, after ${timeSpent} of friendship, you accepted my ${gift}! 🥰`; }; }; } console.log(proposeTo("Sizuka")("3 months")("red rose 🌹")); Each function takes one argument and returns another function — making the code modular, flexible, and easy to reuse. 👉 This is Function Currying — one argument, one step, one perfect result. 🎥 Watch the full short video here: 🔗 https://lnkd.in/g-NkeYBc --- 💡 Takeaway: Function Currying isn’t just a JavaScript trick — it’s a powerful pattern for cleaner, more composable functions that enhance reusability and maintainability in modern frontend code. --- Would love to know: 👉 What’s your favorite JavaScript concept that clicked instantly when you saw it explained simply? #javascript #frontenddevelopment #webdevelopment #coding #programming #softwareengineering #learnjavascript #100daysofjavascript #techsharingan #developers #careergrowth
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