👻 Undefined Ghost vs. Null Void 🚫 I spent too long to fix a bug today: my API sent `{ user: null }`, but my code checked for `undefined`! 🕵️♂️ The result? Unexpected crashes! 💥 🔑 Lesson: - `undefined` = not initialized, doesn’t exist yet - `null` = definitely empty, deliberately no value 👉 Remember: `null === undefined // false` `null == undefined // true` (better to avoid `==`!) Switching my check to `if (user === null)` made my code safer and bug-free. Ever got tripped up by a tiny JavaScript detail? Drop your story below! 👇 #JavaScript #NodeJS #MERNStack #WebDev #CodingTips #DevJourney
"API Bug: undefined vs null in JavaScript"
More Relevant Posts
-
👀 JS Macro vs Micro tasks: A very important concept of JS, often ignored, but can put you in hours long debugging sessions 😂 🧩 Basically, JS doesn’t just have one queue — it has two (if categorized majorly on priority basis): Macrotasks: timers, I/O, setTimeout, etc. Microtasks: promises, queueMicrotask, process.nextTick etc. Microtasks run right after the current stack — before the next macrotask. So even a setTimeout(..., 0) gets delayed behind promises. That’s why code like attached image prints in this order: ``` promise timeout ``` You can read more about this in the article below: https://lnkd.in/gEjWn3_S #JavaScript #NodeJS #EventLoop #AsyncProgramming #WebDevelopment #SoftwareEngineering #LearnInPublic
To view or add a comment, sign in
-
-
💻 Solving “Longest Common Prefix” on LeetCode (JavaScript Edition) Today I solved the “Longest Common Prefix” problem on LeetCode — a classic string challenge that’s simple on the surface but elegant when you find the right approach. 🧩 The challenge: Given an array of strings, return the longest prefix that’s common to all of them. Example: ["flower", "flow", "flight"] → "fl" ⚙️ My solution (JavaScript): Instead of checking every string one by one, I decided to sort the array first. This way, only the first and last words in sorted order need to be compared — because they’ll show the full range of differences in the array. 🧠 Why I like this approach: It’s clean and easy to reason about. Sorting reduces the comparison scope. It demonstrates how a small insight can simplify a problem significantly. 💬 Takeaway: Sometimes the most elegant solutions come from looking at the data differently — not from writing more code. #LeetCode #JavaScript #Coding #ProblemSolving #SoftwareEngineering #LearningJourney
To view or add a comment, sign in
-
-
How TypeScript ‘just knows’ the types from a plain JavaScript library? That magic comes from .𝗱.𝘁𝘀 𝗳𝗶𝗹𝗲𝘀 - Type Declaration files. They don’t contain any logic. They simply describe what a library exposes - the functions, parameters, return types, and more. So when you import something like "lodash", TypeScript instantly provides IntelliSense and type safety. All thanks to @types/lodash, which ships those .d.ts definitions. Without them? No autocomplete. No type hints. Just... guesswork. 😅 Think of .d.ts files as 𝗧𝘆𝗽𝗲𝗦𝗰𝗿𝗶𝗽𝘁’𝘀 𝗱𝗶𝗰𝘁𝗶𝗼𝗻𝗮𝗿𝘆 for JavaScript libraries — helping your editor speak fluent types even when the code doesn’t. Do you remember the first time you realized this? Or ever had to write one yourself? #TypeScript #JavaScript #WebDevelopment #Frontend #DevTips #CodeSmarter #IntelliSense #DefinitelyTyped #DeveloperExperience
To view or add a comment, sign in
-
-
Extracting Types from Arrays Ever needed to get the type of items inside an array without rewriting it manually? You can achieve that with TypeScript as follows ⬇️. const statuses = ["active", "inactive", "pending"] as const; type Status = (typeof statuses)[number]; // "active" | "inactive" | "pending" That is because Arrays in JavaScript are actually objects with numeric keys, So [number] literally means: “Give me the type of whatever is stored at any index in this array.” It even works with arrays of objects: const tabs = [ { label: "Home", value: "/home" }, { label: "About", value: "/about" }, ]; type Tab = (typeof tabs)[number]; // { label: string; value: string; } 💡 This applies the Open/Closed Principle (OCP). #TypeScript #WebDevelopment #Frontend #CodingTips #JavaScript #LearnInPublic
To view or add a comment, sign in
-
-
Going back to basics 🌱 What is JIT Compilation in Javascript ? We have already talked about how Javascript stores data and cleans memory. Now, let us see how it actually runs so fast......!!! Earlier, Javascript used an "interpreter" that executed code line by line simple, but not very fast... Modern "engines" like "V8" (used in Chrome and Node.js) use something smarter called "JIT Compilation"(Just in time Compilation). So it works something like this - 1. The "interpreter" starts running the code immediately. 2. The "JIT compiler" watches which parts run often. 3. It then converts those frequently used parts into "machine code" for faster execution. So, when the same code runs multiple times, Javascript optimises it, so the next executions happen much faster. #Javascript #Frontend
To view or add a comment, sign in
-
💡 VS Code Tip💡 When working on any project, If you're not using ESLint and If we remove some code or comment out some code, we might be left with unused import statements that we might forget to remove. Then we manually need to remove each and every unused import. To avoid such cases, you can configure VS Code to automatically remove unused imports and make proper order of import statements on file save, using the below steps: 1. Press Ctrl + Shift + P or Cmd + Shift + P (Mac) to open command palette in VS Code 2. Type 𝘂𝘀𝗲𝗿 𝘀𝗲𝘁𝘁𝗶𝗻𝗴𝘀 and select 𝗣𝗿𝗲𝗳𝗲𝗿𝗲𝗻𝗰𝗲𝘀: 𝗢𝗽𝗲𝗻 𝗨𝘀𝗲𝗿 𝗦𝗲𝘁𝘁𝗶𝗻𝗴𝘀(𝗝𝗦𝗢𝗡) option 3. Add the following code in the json file "editor.codeActionsOnSave": { "source.organizeImports": "always" }, 4. Save the file and now navigate to any of the file and save it. 5. Your unused imports will be automatically removed and other imports will organized in proper sequence. 𝗣𝗦: 𝗗𝗼𝗻'𝘁 𝗳𝗼𝗿𝗴𝗲𝘁 𝘁𝗼 𝗰𝗵𝗲𝗰𝗸 𝗼𝘂𝘁 𝘁𝗵𝗲 𝗺𝗮𝘀𝘀𝗶𝘃𝗲 𝗼𝗳𝗳𝗲𝗿 𝗼𝗳 𝟵𝟯% 𝗱𝗶𝘀𝗰𝗼𝘂𝗻𝘁 𝗼𝗻 𝘁𝗵𝗲 𝗣𝗿𝗼 / 𝗟𝗶𝗳𝗲𝘁𝗶𝗺𝗲 𝗦𝘂𝗯𝘀𝗰𝗿𝗶𝗽𝘁𝗶𝗼𝗻. 𝗟𝗶𝗻𝗸 𝗶𝗻 𝘁𝗵𝗲 𝗰𝗼𝗺𝗺𝗲𝗻𝘁 𝗮𝗻𝗱 𝗶𝗻 𝘁𝗵𝗲 𝗳𝗲𝗮𝘁𝘂𝗿𝗲𝗱 𝘀𝗲𝗰𝘁𝗶𝗼𝗻 𝗼𝗳 𝗺𝘆 𝗟𝗶𝗻𝗸𝗲𝗱𝗜𝗻 𝗽𝗿𝗼𝗳𝗶𝗹𝗲. #javascript #reactjs #nextjs #webdevelopment
To view or add a comment, sign in
-
-
🚀 Day 812 of #900DaysOfCode 🧠 Understanding the `this` Keyword in JavaScript One of the most confusing yet powerful concepts in JavaScript — the `this` keyword — is something every developer must deeply understand. In today’s post, I’ve covered: ✅ What `this` actually refers to in different contexts ✅ How it behaves inside functions, objects, and classes ✅ Common mistakes developers make ✅ Practical examples to master its behavior If you’ve ever found `this` acting unexpectedly in your code, this post will clear it all up once and for all. 💬 What’s the most confusing part of `this` for you? Share your thoughts in the comments 👇 #Day812 #900DaysOfCode #JavaScript #FrontendDevelopment #WebDevelopment #CleanCode #CodingCommunity #JSBasics #ProgrammingTips
To view or add a comment, sign in
-
🧠 Understanding the `this` Keyword in JavaScript One of the most confusing yet powerful concepts in JavaScript — the `this` keyword — is something every developer must deeply understand. In today’s post, I’ve covered: ✅ What `this` actually refers to in different contexts ✅ How it behaves inside functions, objects, and classes ✅ Common mistakes developers make ✅ Practical examples to master its behavior If you’ve ever found `this` acting unexpectedly in your code, this post will clear it all up once and for all. 💬 What’s the most confusing part of `this` for you? Share your thoughts in the comments 👇 #JavaScript #FrontendDevelopment #WebDevelopment #CleanCode #CodingCommunity #JSBasics #ProgrammingTips
To view or add a comment, sign in
-
🧠 Understanding the `this` Keyword in JavaScript One of the most confusing yet powerful concepts in JavaScript — the `this` keyword — is something every developer must deeply understand. In today’s post, I’ve covered: ✅ What `this` actually refers to in different contexts ✅ How it behaves inside functions, objects, and classes ✅ Common mistakes developers make ✅ Practical examples to master its behavior If you’ve ever found `this` acting unexpectedly in your code, this post will clear it all up once and for all. 💬 What’s the most confusing part of `this` for you? Share your thoughts in the comments 👇 #JavaScript #FrontendDevelopment #WebDevelopment #CleanCode #CodingCommunity #JSBasics #ProgrammingTips
To view or add a comment, sign in
-
🚀 JavaScript/TypeScript Tip: The Double Bang (!!) Operator Ever seen code like this and wondered what’s going on? 👇 const isActive = !!user; Let’s break it down 👇 The double bang (!!) operator is a quick way to convert any value to a boolean in JavaScript or TypeScript. 💡 Here’s how it works: The first ! negates the value (turns truthy → false, falsy → true) The second ! negates it again (bringing it back to the correct boolean form) So instead of: const isActive = Boolean(user); you can write: const isActive = !!user; ⚡ When to use it: Use !! when you want to ensure a value is strictly true or false — for example, in conditions or when returning a clean boolean from a function.
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