All tutorials
Basics

Data Types

Primitives (string, number, boolean, null, undefined, bigint, symbol) and Objects.

1. Explanation

JavaScript has 7 primitive types — string, number, boolean, null, undefined, bigint, symbol — and one non-primitive type: object (which includes arrays and functions). Use typeof to inspect a value's type. Primitives are immutable and compared by value; objects are compared by reference.

2. Example

Try it yourself
Console
Click Run to see output.

3. Expected output

output
string
number
boolean
undefined
object
object
object
function

4. Common mistakes

  • Assuming typeof null returns 'null' — it returns 'object'
  • Using == which performs type coercion: 0 == '' is true
  • Mutating an object you thought was const — const only locks the binding, not the contents

5. Practice questions

  1. Print the typeof for: NaN, [], {}, () => {}, 1n
  2. Convert the string '42' into a number two different ways
  3. Check if a value is exactly null without confusing it with undefined
→ Try more practice problems