Did you know this about JavaScript? In JavaScript: [ ] == ![ ] is true. Wait, what? Here’s why: ![ ] becomes false because an empty array is truthy. So the expression becomes [ ] == false. JavaScript tries to convert both sides to the same type. Number([ ]) is 0, and Number(false) is also 0. Therefore, 0 == 0 → true. This is one of the reasons developers say: "JavaScript is simple… until it isn’t." I’m currently learning JavaScript and finding these little quirks really fascinating. If you’re also learning, what’s the weirdest or most surprising thing you’ve discovered so far? #JavaScript #WebDevelopment #CodingJourney #100DaysOfCode #DidYouKnow #LearnInPublic #FrontendDevelopment
JavaScript's unexpected truthy behavior with arrays and false.
More Relevant Posts
-
💡 JavaScript Challenge: Check if Two Words Are Anagrams Here’s a simple yet powerful JavaScript solution to check if two strings are anagrams of each other 💻 🔍 What’s an Anagram? An anagram is a word formed by rearranging the letters of another — for example: 👉 listen → silent ✅ 👉 hello → world ❌ 🧠 Logic Behind the Code: Compare lengths of both strings. Count occurrences of each character in the first string. Decrease the count for each character in the second string. If all counts match, they’re anagrams! #JavaScript #CodingChallenge #100DaysOfCode #WebDevelopment #ProblemSolving
To view or add a comment, sign in
-
-
Lately, I’ve been revisiting some core JavaScript concepts, and today I stumbled upon something I hadn’t really paid attention to before — Symbols. They’re not something you see in everyday code, but I found them really interesting. A Symbol is a unique and immutable value that can be used as a key in objects. What I like about Symbols is that each one is completely unique, even if it has the same description: Symbol("id") === Symbol("id"); // false They can be super useful when you need unique property keys in an object — especially to avoid accidental overwriting. Even if I might not use them often, I enjoy discovering these little parts of JavaScript that make the language more powerful than it first seems. #JavaScript #WebDevelopment #LearningEveryDay
To view or add a comment, sign in
-
-
"this" in JavaScript isn’t what you think it is. It doesn’t mean “this function”, it means “the object that called the function.” That’s why "this" changes depending on how the function is called. Arrow functions don’t have their own this. They inherit it from their parent scope, perfect for callbacks, but confusing inside classes and objects. That’s why in React or classes you often see .bind(this) in event handlers because without it, "this" gets lost when the function runs. So next time "this" is undefined, remember, It’s not you. It’s JavaScript being… JavaScript. #this #javascript
To view or add a comment, sign in
-
❓ Are “undefined” and “not defined” the same in JavaScript? Not really. In JavaScript, every declared variable automatically gets the placeholder undefined during the memory allocation phase — meaning the variable exists, but no value has been assigned yet. However, if you try to access a variable that was never declared, JavaScript throws not defined. ➡️ Undefined = declared but not assigned ➡️ Not Defined = not declared at all JavaScript is also a loosely typed language, so variables can change types freely. 💡 Pro tip: Never manually assign undefined. Let JavaScript handle that. #JavaScript #WebDevelopment #Programming #Frontend #LearningJS
To view or add a comment, sign in
-
🚀 5 Fun Facts About JavaScript You Might Not Know! JavaScript is full of surprises — sometimes weird, but always fun! 😄 Here are a few things that make JS so unique 👇 1️⃣ 🧠 Everything is an Object (almost!) Functions, Arrays, Dates, even Regular Expressions — all are objects in disguise. Only null, undefined, boolean, string, number, and symbol are primitives. 2️⃣ 🔢 NaN is actually a Number 😅 Try this: typeof NaN → "number" Yes, it’s “Not a Number,” but its type is number! 3️⃣ ➕ You can add strings and numbers easily 5 + "5" → "55" Because JavaScript does type coercion automatically. 4️⃣ 🧩 Functions can return functions! That’s called a closure, and it’s one of JS’s most powerful features. 5️⃣ ⚙️ The JS engine doesn’t sleep 😴 Even if your code looks simple, the event loop is always running behind the scenes managing tasks asynchronously. #softwareengineering #mernstackdevelopment #softwaredeveloper #JavaScript #WebDevelopment #CodingLife
To view or add a comment, sign in
-
-
💡 JavaScript Trivia: Did you know that in JavaScript, the expression NaN === NaN actually returns false? 🤯 That’s because NaN (Not-a-Number) is special — it’s not equal to anything, not even itself. This behavior follows the IEEE 754 standard for floating-point numbers. So if NaN isn’t equal to itself, how do we check for it? That’s where isNaN() and Number.isNaN() come in. The older isNaN() function tries to convert the value into a number before checking, which can give confusing results — for example, isNaN('hello') returns true because the string can’t be turned into a number. The newer Number.isNaN() is smarter and stricter: it only returns true when the value is literally NaN, not just something that can’t be converted to a number. ✅ Best practice: use Number.isNaN() whenever possible — it’s more predictable and avoids type coercion headaches. A tiny quirk, but one that’s tripped up many JavaScript devs (including me at some point 😅). #JavaScript #WebDevelopment #CodingTips #Programming #Trivia #Fact
To view or add a comment, sign in
-
-
🚀 Understanding JavaScript: '' vs null vs undefined In my journey as a developer, I’ve found that some of the smallest details make a big difference. One such detail: knowing when to use an empty string (''), null, or undefined. Let’s break it down simply: 🔹 let var1 = '' This is an empty string. You're saying: "I have a string variable, but it currently holds no characters." Type is “string”. 🔹 let var2 = null This is a deliberate assignment of "no value". Use it when you expect a value later, but for now there’s nothing. It signals intention. 🔹 let var3 = undefined This means the variable exists, but is not yet assigned a value (or hasn’t been set explicitly). It’s more a default state than a deliberate one. 🎯 Why this matters Using the wrong one can lead to bugs or confusion for you (and your team) when reading code. Empty strings, null, and undefined each have different behaviours in comparisons, type checks, and program logic. Being intentional improves readability and maintainability of your code. 👉 Takeaway: Use '' when you want a string that doesn’t have content yet. Use null when you know a value will come later, but now there isn’t one. Accept that undefined is often what you get when you forget to assign, rather than something you deliberately choose. 💬 I’d love to hear from you: do you use null deliberately in your code, or mostly rely on undefined? How do you decide between them? Drop your thoughts below. #JavaScript #CodingTips #WebDevelopment #Programming #SoftwareEngineering
To view or add a comment, sign in
-
👉✅ “Setting a one-week goal to revise JavaScript again.” 💻Topic-1. JavaScript Constructor Function Hey everyone, 👋 Today, let’s talk about an interesting JavaScript topic — the Constructor Function. This is a special type of function that helps us create multiple similar objects without writing the same code again and again! 🔁 🧠 Key points to understand: The name of a constructor function always starts with a capital letter. We use the new keyword when creating an object. It automatically returns a new object. Through this concept, we can explore the basics of Object-Oriented Programming (OOP) in JavaScript — including concepts like inheritance and encapsulation. 🚀 If you’re learning JavaScript, understanding constructor functions is a must-have skill — it makes your code cleaner, reusable, and more efficient! #JavaScript #WebDevelopment #CodingTips #ConstructorFunction #FrontendDevelopment #LearningEveryday
To view or add a comment, sign in
-
-
What is This? hey, where are you looking? I mean 'this' key word in javascript! here is a quick referesh: In JavaScript, the keyword this confuses many developers. But there’s a simple way to think about it: this is like saying “I”. When someone says “I am hungry”, the meaning depends on who is speaking — not the sentence itself. JavaScript works the same way: - When a function belongs to an object, this means the object that is speaking - When a regular function is called on its own, the speaker can change depending on how it’s called - Arrow functions don’t define their own “I” — they borrow it from the surrounding context 📌 The mindset: Don’t ask “What does this mean?” — ask “Who is talking?” Once you focus on who the speaker is, this becomes much easier to understand. 💬 Question: What was your first confusion about 'this' in JavaScript? #JavaScript #WebDevelopment #Programming #Frontend #CodingTips #React #NodeJS #LearningToCode
To view or add a comment, sign in
-
🚀 Day 9 of My 30 Days of JavaScript Journey ✅ Challenge: Arguments Length (LeetCode #2703) Write a function argumentsLength that returns the total number of arguments passed to it — no matter how many or what type! This challenge is a simple yet powerful way to understand rest parameters in JavaScript. 💻 Language Used: JavaScript ❓ Problem Link: https://lnkd.in/g8gK65Cp 💡 Solution: https://lnkd.in/gJQyNBaq 🧠 Concept Highlighted: This problem emphasizes the use of rest parameters (...args) to handle variable-length arguments, a handy feature for building flexible and reusable functions in JavaScript. #Day9 #JavaScript #LeetCode #30DaysOfCode #CodingChallenge #WebDevelopment #FrontendDevelopment #LearningEveryday #ProblemSolving #ES6
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