DevPrep
  • Interview Prep
  • Projects
  • Resources
  • Pricing
  • About Us
Submit Question
DevPrep
  • Pricing
  • About Us
Submit Question
← From Beginner to Expert in Fundamentals of Frontend
  • Scope & Closures
  • Asynchronous JavaScript
  • DOM Manipulation
  • ES6+ to 2026
  • Execution Context & Call Stack
  • Hoisting: var, let, const & Functions
  • Data Types & Type Coercion
  • Prototypes & the this Keyword
  • The Event Loop Deep Dive
  • Higher-Order Functions, Currying & Functional Patterns
  • Callbacks, Promises & Async/Await
  • Event Delegation & DOM Optimization
  • Destructuring, Spread/Rest & Modern Syntax
  • ES Modules & the Fetch API
  • Memory Management & Garbage Collection
  • Debouncing, Throttling & Performance Patterns
  • Design Patterns in JavaScript
  • Proxies, Reflect & Symbols
  • JavaScript Optimizations & Best Practices
  • JavaScript Interview Questions (30 MCQs)
← From Beginner to Expert in Fundamentals of Frontend

Data Types & Type Coercion

20 min read
PrimitivesReference TypesType Coercion== vs ===Falsy ValuestypeofNaN

JavaScript's Type System

JavaScript is dynamically typed — variables don't have fixed types. There are 7 primitive types and 1 structural type.

Primitive vs Reference Types

Primitives (Immutable)Reference (Mutable)
stringObject
numberArray
bigintFunction
booleanMap / Set
undefinedDate / RegExp
null
symbol

The typeof Operator Quirks

typeof "hello"     // "string"
typeof 42          // "number"
typeof true        // "boolean"
typeof undefined   // "undefined"
typeof null        // "object"  ← FAMOUS BUG (since 1995!)
typeof []          // "object"  ← Arrays are objects
typeof function(){} // "function"

Type Coercion: == vs ===

== performs type coercion (converts types before comparing). === checks value AND type (strict equality).

Expression=====Why
0 == ""truefalseBoth coerce to 0
0 == "0"truefalse"0" → 0
"" == "0"falsefalseDifferent strings
null == undefinedtruefalseSpecial rule in spec
NaN == NaNfalsefalseNaN ≠ anything

Falsy Values (All 8)

// These are ALL the falsy values in JS:
false, 0, -0, 0n, "", null, undefined, NaN

// Everything else is truthy, including:
// "0", "false", [], {}, function(){}

Implicit Coercion Traps

console.log(1 + "2");    // "12" (number → string)
console.log("6" - 1);    // 5   (string → number)
console.log(true + true); // 2   (boolean → number)
console.log([] + []);     // ""  (arrays → strings → concat)
console.log({} + []);     // "[object Object]" or 0
console.log([] + {});     // "[object Object]"

Safe Type Checking

// Use these instead of typeof for edge cases:
Array.isArray([]);           // true
Number.isNaN(NaN);           // true (not global isNaN!)
Number.isFinite(42);         // true
Object.prototype.toString.call(null); // "[object Null]"

Practice

  • JavaScript
  • DSA
  • Machine Coding
  • System Design

Resources

  • Learning Tracks
  • Articles
  • Roadmaps
  • Compare Concepts
  • Glossary
  • Developer Tools
  • All Questions

Company

  • About
  • Pricing

Legal

  • Privacy Policy
  • Terms of Service
DevPrep

© 2026 DevPrep. All rights reserved.