Primitive Types
// String — text
const name = "Alice";
const greeting = `Hello, ${name}!`; // template literal
// Number — integers and decimals (one type)
const age = 25;
const price = 9.99;
const big = 1_000_000; // underscores for readability
// Boolean
const isLoggedIn = true;
const isEmpty = false;
// Undefined — declared but not assigned
let x;
console.log(x); // undefined
// Null — intentional absence of value
const data = null;
// BigInt — integers too large for Number
const huge = 9007199254740993n;
// Symbol — unique identifier (advanced)
const id = Symbol("id");The Object Type
// Object
const user = { name: "Alice", age: 25 };
// Array (is an object)
const colours = ["red", "green", "blue"];
// Function (is an object)
function add(a, b) { return a + b; }Checking Types
typeof "hello" // "string"
typeof 42 // "number"
typeof true // "boolean"
typeof undefined // "undefined"
typeof null // "object" ← famous JS quirk
typeof [] // "object"
typeof {} // "object"
typeof function(){} // "function"
// Better check for arrays:
Array.isArray([1, 2, 3]) // trueType Coercion
"5" + 3 // "53" (number coerced to string)
"5" - 3 // 2 (string coerced to number)
"5" * "2" // 10
Boolean("") // false
Boolean("hello") // true
Boolean(0) // false
Boolean(1) // trueUse
=== (strict equality) not == — strict equality checks both value AND type, avoiding coercion surprises. "5" == 5 is true, but "5" === 5 is false.