Comparing Sets in JavaScript With difference() and symmetricDifference() How the new Set methods difference() and symmetricDifference() can replace verbose Set comparisons with clear, expressive code. https://lnkd.in/dZT4jg-4 #javascript
JavaScript Set difference() and symmetricDifference() methods
More Relevant Posts
-
🔍 JavaScript Bug You Might Have Seen (typeof null === "object") You write this: console.log(typeof null); // ? What do you expect? 👉 "null" But you get: 👉 "object" 🤯 Wait… null is NOT an object… So why is JavaScript saying this? This happens because of a historical bug in JavaScript 📌 What’s going on? In the early days of JavaScript: 👉 Values were stored in a low-level format 👉 Objects were identified by a specific type tag Unfortunately… 👉 null was given the same tag as objects So: typeof null === "object" 📌 Important point: 👉 This is NOT correct behavior 👉 But it was never fixed (for backward compatibility) 📌 So how do you check for null? ❌ Don’t do this: typeof value === "null" ✔ Do this instead: value === null 💡 Takeaway: ✔ typeof null returns "object" (bug) ✔ It’s a legacy behavior in JavaScript ✔ Always check null using === null 👉 Not everything in JavaScript makes sense… some things just stayed for history 😄 🔁 Save this before it confuses you again 💬 Comment “null” if this surprised you ❤️ Like for more JavaScript deep dives #javascript #frontend #codingtips #webdevelopment #js #developer
To view or add a comment, sign in
-
🔍 JavaScript Bug You Might Have Seen (typeof null === "object") You write this: console.log(typeof null); // ? What do you expect? 👉 "null" But you get: 👉 "object" 🤯 Wait… null is NOT an object… So why is JavaScript saying this? This happens because of a historical bug in JavaScript 📌 What’s going on? In the early days of JavaScript: 👉 Values were stored in a low-level format 👉 Objects were identified by a specific type tag Unfortunately… 👉 null was given the same tag as objects So: typeof null === "object" 📌 Important point: 👉 This is NOT correct behavior 👉 But it was never fixed (for backward compatibility) 📌 So how do you check for null? ❌ Don’t do this: typeof value === "null" ✔ Do this instead: value === null 💡 Takeaway: ✔ typeof null returns "object" (bug) ✔ It’s a legacy behavior in JavaScript ✔ Always check null using === null 👉 Not everything in JavaScript makes sense… some things just stayed for history 😄 🔁 Save this before it confuses you again 💬 Comment “null” if this surprised you ❤️ Like for more JavaScript deep dives #javascript #frontend #codingtips #webdevelopment #js #developer
To view or add a comment, sign in
-
Most JS bugs come from one thing — not knowing when JavaScript secretly converts your types for you. New blog post → Type Casting vs Type Coercion in JavaScript Covers: • What coercion actually is • How to write safer code https://lnkd.in/dQMaKZbH #javascript #WebDev #100DaysOfCode
To view or add a comment, sign in
-
I’ve watched so many explanations about arrow functions in JavaScript… and almost all of them say the same thing: “Arrow functions are just shorter syntax.” That never felt right to me. Because if it was just syntax, JavaScript wouldn’t need a whole new function type. The real difference is not how they look. It’s how they behave. In JavaScript, normal functions don’t “remember” "this". They wait until they are called… and then decide what "this" should be. So the same function can behave differently depending on how you invoke it. That’s where most confusion actually comes from. Arrow functions changed this completely. They don’t create their own "this". Instead, they capture "this" from the surrounding scope at the time they are created. And once captured, it never changes. So the real difference is simple: Normal function → "this" is decided at call time Arrow function → "this" is fixed at creation time So no, arrow functions are not just about shorter syntax. They are about removing uncertainty. Once you understand this, a lot of JavaScript weirdness suddenly starts making sense. Full breakdown: https://lnkd.in/gVdMH_42
To view or add a comment, sign in
-
🚀 Mastering Closures in JavaScript – A Real-World Example One of the most powerful (and often misunderstood) concepts in JavaScript is the closure. Think of it as a backpack 🎒 that an inner function carries, filled with variables from its outer function—even after the outer function has finished running. Here’s a neat example: function logWithPrefix(prefix: string): (message: string) => void { // Inner function remembers 'prefix' return function (message: string) { log(`${prefix} | ${message}`); }; } // Create loggers with different "backpacks" const infoLogger = logWithPrefix('INFO'); const errorLogger = logWithPrefix('ERROR'); infoLogger('Hello World!'); // Output: "INFO | Hello World!" errorLogger('Something went wrong!'); // Output: "ERROR | Something went wrong!" function log(message: string): void { console.log(message); } 💡 What’s happening here? logWithPrefix creates a closure. The inner function remembers the prefix variable, even after logWithPrefix has returned. This allows us to build reusable, context-aware loggers (INFO, ERROR, etc.) without repeating code. 👉 Closures are everywhere: event handlers, callbacks, and even frameworks like React rely on them. Once you grasp this, you unlock a new level of JavaScript power. 🔑 Takeaway: Closures = memory + reusability + cleaner code. ✨ If you found this useful, imagine how closures can simplify your next project. Keep experimenting, and you’ll see them pop up more often than you think! #JavaScript #TypeScript #Closures #WebDevelopment #CleanCode #InterviewPrep #LearningEveryday #TechLeadership
To view or add a comment, sign in
-
-
🚀 Why Does null Show as an Object in JavaScript? 🤯 While practicing JavaScript, I came across something interesting: let myVar = null; console.log(typeof myVar); // Output: object At first, it feels confusing… why is null an object? 🤔 💡 Here’s the simple explanation: null is actually a primitive value that represents "no value" or "empty". But when JavaScript was first created, there was a bug in the typeof operator. Due to this bug, typeof null returns "object" instead of "null". ⚠️ This behavior has been kept for backward compatibility, so changing it now would break existing code. 🔍 Key Takeaways: null → means "nothing" (intentional empty value) typeof null → returns "object" (this is a historical bug) Objects (like {}) also return "object" 💻 Example: let myObj = { name: "John" }; console.log(typeof null); // object ❌ (bug) console.log(typeof myObj); // object ✅ (correct) 📌 Conclusion: Even though both return "object", they are completely different in meaning. 👉 JavaScript is powerful, but it has some quirky behaviors—this is one of them! #JavaScript #WebDevelopment #CodingJourney #100DaysOfCode #FrontendDevelopment
To view or add a comment, sign in
-
-
Javascript: Variable naming rules 🚀 New to JavaScript? Your variable names might be breaking the rules! Many beginners start writing JavaScript quickly… but forget that variable naming has important rules. Good variable names make your code clean, readable, and professional. Here are some simple JavaScript variable naming rules every beginner should know: • Must start with a letter, _ (underscore), or $ (dollar sign) Example: name, _count, $price • Cannot start with a number ❌ 1value → Invalid ✅ value1 → Correct • No spaces allowed in variable names ❌ user name ✅ userName • JavaScript is case-sensitive age, Age, and AGE are different variables • Avoid JavaScript reserved keywords ❌ let let = 5; Keywords like let, const, if, class cannot be used as variable names. 💡 Pro Tip: Use camelCase for clean and readable code. Example: userAge, totalPrice, isLoggedIn Clean naming = Clean code. #JavaScript #WebDevelopment #ProgrammingBasics #FrontendDevelopment #LearnToCode #CodingForBeginners #SoftwareDevelopment #JavaScriptTips #CleanCode #DeveloperCommunity
To view or add a comment, sign in
-
-
𝗧𝗵𝗲 𝗣𝗼𝘄𝗲𝗿 𝗼𝗳 𝗖𝗮𝗹𝗹𝗯𝗮𝗰𝗸𝘀 𝗶𝗻 𝗝𝗮 v𝗮𝗦𝗰𝗿𝗶𝗽𝘁 JavaScript is powerful. It can handle tasks that take time, like API calls or timers. You need a way to manage these tasks. That's where callbacks come in. A callback is a function passed into another function to be executed later. You can store functions in variables, pass them as arguments, and return them from other functions. - You can pass a function as an argument to another function - You can return a function from another function - You can store a function in a variable Callbacks help with asynchronous operations. JavaScript doesn't wait for long tasks to finish. It keeps running other tasks. Callbacks run after a task is complete. They are used in event handling, like when a button is clicked. Callbacks can become messy when nested. This is called "callback hell". It's hard to read, debug, and maintain. To avoid this, you can use other methods like Promises and Async/Await. Callbacks are important in JavaScript. They enable asynchronous behavior and flexible function execution. They power many built-in features. But you should use them wisely to avoid messy code. Source: https://lnkd.in/g3jd_H2S
To view or add a comment, sign in
-
🔥 Understanding callback functions in JavaScript! 🚀 Callback functions are functions passed as arguments to other functions to be executed later. They are commonly used in event handling, asynchronous actions, and more. ⚡️ Why it matters: Callback functions allow developers to write more flexible and reusable code. They are essential in handling tasks that need to be executed at a specific time. 🔹 Step by step breakdown: 1️⃣ Define the main function that will execute the callback. 2️⃣ Create the callback function to be passed as an argument. 3️⃣ Call the main function and pass the callback as an argument. 👨💻 Code example: ```javascript function mainFunction(callback) { // Do something callback(); } function callbackFunction() { console.log('Callback executed!'); } mainFunction(callbackFunction); ``` 💡 Pro tip: Keep callback functions simple and focused on a specific task for better code readability. ⚠️ Common mistake: Forgetting to invoke the callback within the main function, resulting in the function not executing as intended. ❓ Have you ever used callback functions in your projects? Share your experiences below! 💬 🌐 View my full portfolio and more dev resources at tharindunipun.lk #JavaScript #CallbackFunctions #AsyncProgramming #CodeNewbie #WebDevelopment #LearnToCode #DeveloperTips #FunctionCallbacks #EventHandling #AsynchronousJavaScript
To view or add a comment, sign in
-
-
🔍 JavaScript Quirk: Hoisting (var vs let vs const) JavaScript be like: 👉 “I know your variables… before you even write them” 😅 Let’s see the magic 👇 console.log(a); var a = 10; 💥 Output: undefined Wait… no error? 🤯 Why? Because `var` is **hoisted** 📌 What is Hoisting? Hoisting is JavaScript’s behavior of **moving variable and function declarations to the top of their scope before execution**. 👉 JS internally does this: var a; console.log(a); // undefined a = 10; So the variable exists… but has no value yet. Now try with `let` 👇 console.log(b); let b = 20; 💥 Output: ReferenceError ❌ Same with `const` 👇 console.log(c); const c = 30; 💥 Error again ❌ Why? Because `let` & `const` are also hoisted… BUT they live in something called: 👉 “Temporal Dead Zone” (TDZ) Translation: 🧠 “You can’t touch it before it’s declared” --- 💡 Simple Breakdown: ✔ `var` → hoisted + initialized as `undefined` ✔ `let` → hoisted but NOT initialized ✔ `const` → same as let (but must assign value) 💀 Real dev pain: Using `var`: 👉 “Why is this undefined?” Using `let`: 👉 “Why is this error?” JavaScript: 👉 “Figure it out yourself” 😎 💡 Takeaway: ✔ Avoid `var` (legacy behavior) ✔ Prefer `let` & `const` ✔ Understand hoisting = fewer bugs 👉 JS is not weird… You just need to know its secrets 😉 🔁 Save this before hoisting confuses you again 💬 Comment “TDZ” if this finally made sense ❤️ Like for more JS quirks #javascript #frontend #codingtips #webdevelopment #js #developer
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