JavaScript has one of the most famous quirks in programming: 👉 typeof null === "object" Yes… really. But why? Back in the early implementation of JavaScript (1995), values were stored in memory using type tags. Objects had a type tag of 0. Unfortunately, null was represented as a null pointer (0x00). When typeof checked the type tag, it saw 0 and returned "object". That bug shipped. And because fixing it would break massive amounts of existing code, it stayed. So what’s the real issue? Because of this: typeof null === "object" You cannot safely check for objects like this: typeof value !== "object" Why? Because null is not an object - but JavaScript says it is. The correct way to check: if (value !== null && typeof value === "object") { // safe object check } Or more explicitly: if (value && typeof value === "object") (when you’re okay excluding null and other falsy values) This is one of those historical decisions that shaped JavaScript forever. It’s not a feature. It’s a legacy artifact. And knowing it separates beginners from engineers who understand the language deeply. Akash Kadlag Hitesh Choudhary Jay Kadlag Chai Aur Code #JavaScript #WebDevelopment #Programming #LearningInPublic
JavaScript's Quirky typeof null ===
More Relevant Posts
-
JavaScript is one of the most widely used languages in the world, yet it still carries a few historical quirks that were never fixed because changing them would break existing code. Over time, developers accepted them and simply moved on. Here are two classic examples: 1. "console.log(typeof null)" Output → ""object"" Logically, this should return ""null"". This behavior comes from an early implementation bug in JavaScript’s type system. By the time it was discovered, too many systems relied on it, so it became part of the language specification. 2. "console.log(typeof console.log)" Output → ""function"" Technically, functions in JavaScript are objects. So although ""function"" feels like a special type, it is actually a callable object. The language chose to expose this distinction through "typeof", which can be confusing at first. These small inconsistencies remind us that programming languages evolve over time. Not every design decision is perfect, but stability and backward compatibility often matter more than perfection. Understanding these nuances is what separates someone who writes code from someone who truly understands the language. #JavaScript #SoftwareDevelopment #Programming #WebDev
To view or add a comment, sign in
-
🚀 Day 37/50 – Callback Functions in JavaScript Today I learned about Callback Functions in JavaScript — a powerful concept used in asynchronous programming. 🔹 A callback function is a function passed as an argument to another function and executed later. 🔹 It helps JavaScript handle tasks like API calls, timers, and events efficiently. 📌 Basic Example function greet(name, callback) { console.log("Hello " + name); callback(); } function sayBye() { console.log("Goodbye!"); } greet("Priyanka", sayBye); ✅ Here, sayBye is the callback function. 📌 Callback with setTimeout (Asynchronous Example) setTimeout(function() { console.log("This runs after 2 seconds"); }, 2000); ✔ The function executes after a delay. ✔ JavaScript continues running other code meanwhile. 📌 Why Callbacks are Important? ✅ Handle asynchronous operations ✅ Improve code flexibility ✅ Used in event handling and API requests 💡 Key Learning: JavaScript executes code asynchronously, and callbacks help control when a function should run. Learning step by step, growing day by day 💻✨ #Day37 #50DaysOfCode #JavaScript #AsyncProgramming #WebDevelopment #CodingJourney #LearningInPublic
To view or add a comment, sign in
-
-
🚀 Post #01 Why modern JavaScript developers prefer "let" over "var" When learning JavaScript, one of the first things many developers notice is that older code uses "var", while modern code uses "let". This shift happened for important technical reasons. 🔹 The problem with "var": Function scope Variables declared with "var" are function-scoped, not block-scoped. This means they can be accessed outside the block where they were created, which can lead to unexpected behavior and bugs. Example: if (true) { var x = 10; } console.log(x); // 10 ❌ (still accessible) 🔹 The advantage of "let": Block scope Variables declared with "let" are block-scoped, meaning they only exist inside the block where they are defined. This makes code more predictable and safer. Example: if (true) { let y = 20; } console.log(y); // Error ✅ (correct behavior) 🔹 Why modern developers use "let": • Prevents accidental variable access • Reduces bugs caused by scope confusion • Makes code cleaner and easier to maintain • Follows modern JavaScript (ES6+) standards 📌 Conclusion: "var" is not completely removed, but it is considered outdated in modern development. Today, developers use "let" (and "const") to write safer, more reliable, and professional JavaScript code. #JavaScript #WebDevelopment #Programming #Coding #LearningJourney
To view or add a comment, sign in
-
-
JavaScript Deep Dive [Master Functions part-2] : this, Arrow Functions & More.. One of the most confusing topics in JavaScript is how the this keyword behaves in different situations. Many developers struggle with the difference between regular functions and arrow functions. To make this concept easier, I’ve shared a new PDF: “Mastering JavaScript Context: this & Arrow Functions.” In this guide, you’ll learn: ✅ How this works in JavaScript execution context ✅ The key difference between regular functions and arrow functions ✅ Dynamic runtime binding vs lexical binding ✅ Why arrow functions don’t have their own this ✅ Practical insights into IIFEs and function execution and more. Understanding function context is critical for writing clean, predictable, and bug-free JavaScript, especially when working with objects, event handlers, and modern frameworks. 📄 Check out the PDF and share your thoughts. 🔰 check out First Part of Mastering Functions on my profile. #JavaScript #JavaScriptDeveloper #WebDevelopment #FrontendDevelopment #Programming #Coding #SoftwareDevelopment #LearnJavaScript #JSFunctions #ArrowFunctions #DeveloperCommunity #MERN #learnJavascript #learnReact #js #adityathakor #aditya
To view or add a comment, sign in
-
⚡ Ever wondered why your JavaScript code runs in a specific order? The answer lies in something called the Call Stack. Every time a function runs, JavaScript adds it to the stack. When the function finishes, it gets removed. Simple rule it follows: 📦 LIFO — Last In, First Out That means the last function added is the first one removed. 🚨 And yes… That scary error — “Maximum call stack size exceeded” It happens when functions keep getting added to the stack without stopping. Eventually, memory fills up… and the program crashes. 🎯 Why understanding the Call Stack matters: ✔ Helps you understand execution order ✔ Makes debugging easier ✔ Builds strong recursion fundamentals ✔ Makes you interview-ready Mastering the Call Stack is one of the first real steps toward truly understanding JavaScript. #JavaScript #WebDevelopment #FrontendDeveloper #Programming #LearnToCode #Developers #Tech
To view or add a comment, sign in
-
-
Just published a new blog on JavaScript Operators. In this article, I break down: • Arithmetic operators • Comparison operators (== vs === explained clearly) • Logical operators • Assignment operators • Simple console examples for real understanding If you are starting with JavaScript, mastering operators makes everything easier, from conditions to loops to real projects 👇 https://lnkd.in/gSmpqBCn Special thanks to Hitesh Choudhary Chai Aur Code Piyush Garg Akash Kadlag Jay Kadlag for guidance! #JavaScript #WebDevelopment #FrontendDevelopment #Programming #Coding #100DaysOfCode #LearnToCode #TechWriting
To view or add a comment, sign in
-
Most tutorials show how to write if, else, and switch, but they rarely explain how control flow actually works when the code runs. So I wrote a short blog explaining: • What control flow means in programming • The if statement • The if...else statement • The else if ladder • How the switch statement works • Why break is important in switch If you're learning JavaScript, this should help you understand how decision making works in code. https://lnkd.in/gUMYNnZ3 Thanks to Hitesh Choudhary Chai Aur Code Akash Kadlag Jay Kadlag Piyush Garg for guidance. #javascript #webdevelopment #programming #frontenddevelopment #coding #100daysofcode #learntocode
To view or add a comment, sign in
-
JavaScript looks simple… until someone asks: "When should you use var, let or const?" 🤔 Understanding this properly separates beginners from confident developers. 🔹 var – Function scoped – Can be reassigned & redeclared – Hoisted (initialized as undefined) – Old school way 🔹 let – Block scoped – Can be reassigned – Cannot be redeclared in same block – Hoisted but in Temporal Dead Zone – Modern best practice for changing values 🔹 const – Block scoped – Cannot be reassigned – Cannot be redeclared – Also in Temporal Dead Zone – Best practice by default 💡 Golden Rule: 👉 Prefer const by default 👉 Use let only when reassignment is needed 👉 Avoid var in modern JavaScript Strong fundamentals in JavaScript save you from hidden bugs and scope-related nightmares later. Which one do you use most in your projects? 👇 #JavaScript #WebDevelopment #FrontendDevelopment #NodeJS #Programming #CodingTips #FullStackDeveloper #LearnToCode #SoftwareEngineering #DeveloperLife
To view or add a comment, sign in
-
-
JavaScript Array Methods Every Developer Should Know 👨💻 Arrays are one of the most commonly used data structures in JavaScript. When you understand array methods well, your code becomes cleaner, shorter, and easier to maintain. Here are some important methods every developer should know: 🔹 map() – Transforms each element in an array and returns a new array. 🔹 filter() – Selects elements that match a specific condition. 🔹 reduce() – Converts the entire array into a single value (great for totals, counts, and data processing). 🔹 find() – Returns the first element that matches a condition. 🔹 some() – Checks if at least one element satisfies a condition. 🔹 every() – Checks if all elements satisfy a condition. Mastering these methods helps you write more efficient JavaScript and improves your problem-solving skills in real projects. Which JavaScript array method do you use the most? 🤔 #JavaScript #WebDevelopment #FrontendDeveloper #Coding #Programming #100DaysOfCode
To view or add a comment, sign in
-
-
Functions are the heart of JavaScript, but how you define them matters more than you might think! I’ve just released a new blog post diving deep into the nuances between Function Declarations and Function Expressions. In this guide, I cover: ✅ Core Syntax – How to write both types correctly. ✅ The "Write Once, Use Anywhere" Philosophy – Why functions are essential for reusable code. ✅ Hoisting & Execution – Understanding the critical differences in how the JS engine handles these functions. ✅ Practical Use Cases – When to choose one over the other in your projects. This post simplifies these concepts using clear language and examples to help you avoid common pitfalls. A huge thanks to Hitesh Choudhary sir and Piyush Garg sir for explaining hoisting and function logic in such a simple, memorable way! Check out the full comparison here: https://lnkd.in/gmvhxbHS #JavaScript #WebDevelopment #Programming #CleanCode #LearningToCode #Hashnode #TechCommunity Akash Kadlag | Jay Kadlag
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