Skip to content

Day 3: Primitive Data Types & typeof

Master JavaScript’s core primitive types and inspect element types using the typeof operator.

  • string: Text characters wrapped in quotes: 'Hello', "World".
  • number: Integers and floating-point decimals: 42, 3.14159, -10.
  • boolean: Logical truth values: true or false.
  • undefined: A variable that has been declared but not yet assigned a value.
  • null: An intentional assignment representing “no value” or “empty”.
const title = 'JavaScript Course';
const price = 49.99;
const isPublished = true;
let discount; // undefined
const coupon = null; // intentional empty value
console.log(typeof title); // "string"
console.log(typeof price); // "number"
console.log(typeof isPublished); // "boolean"
console.log(typeof discount); // "undefined"
console.log(typeof coupon); // "object" (historical JavaScript quirk!)
  1. Declare a variable for each primitive type and log its value along with its typeof.
  2. Observe what happens when you perform mathematical operations between numbers and strings like '5' + 2 vs '5' - 2.