Interview answer drill

Use this JavaScript interview question to rehearse a quick answer, common mistake, follow-up, and production pitfall.

What are the various data types in JavaScript?Frontend interview answer

HighEasyJavascript
Interview focus

This JavaScript interview question tests whether you can explain the data types in JavaScript, connect it to production trade-offs, and handle common follow-up questions.

  • the data types in JavaScript explanation without falling back to memorized docs wording
  • Data Types and Basics reasoning, edge cases, and production failure modes
  • How you would answer the most likely JavaScript interview follow-up
Practice more JavaScript interview questions
Interview quick answer

JavaScript has eight main data types: seven primitives (string, number, bigint, boolean, undefined, symbol, null) and one non-primitive type (object). Understanding which values are primitive vs object helps with comparisons, copying, and mutation behavior. This affects state updates, copying, and performance; test typeof null and array detection.

Full interview answer

The Core Idea\n\nJavaScript values fall into two main categories:\n- Primitive types — stored directly, immutable, and compared by value.\n- Non-primitive type — objects, which are mutable and compared by reference.\n\nThere are 8 total data types in JavaScript (as of ES2020).

Category

Data Type

Description

Example

Primitive

Number

Represents both integers and floating-point numbers.

42, 3.14, NaN

Primitive

String

Represents text data enclosed in quotes.

'Hello', \"World\", Hi

Primitive

Boolean

Represents true/false values.

true, false

Primitive

Undefined

A variable that has been declared but not assigned a value.

let x; console.log(x); // undefined

Primitive

Null

An intentional empty value (represents 'nothing').

let y = null;

Primitive

Symbol

A unique and immutable value often used as object keys.

const id = Symbol('id');

Primitive

BigInt

Used for integers larger than 2^53 - 1.

12345678901234567890n

Non-Primitive

Object

Used to store collections of data and more complex entities.

{ name: 'Alice', age: 25 }

JavaScript data types at a glance.

Primitives Are Immutable\n\nPrimitive values can’t be changed directly — any modification creates a new value instead.\n\n``javascript\nlet str = 'Hi';\nstr[0] = 'Y'; // ❌ has no effect\nconsole.log(str); // 'Hi'\n``

Objects Are Mutable\n\nObjects, arrays, and functions can be modified because they are stored by reference.

JAVASCRIPT
const user = { name: 'Alice' };\nconst ref = user;\nref.name = 'Bob';\nconsole.log(user.name); // 'Bob' (same reference)
                  

Common Confusion\n\ntypeof null returns 'object' — this is a well-known JavaScript quirk kept for backward compatibility.

JAVASCRIPT
console.log(typeof null); // 'object'
                  

Practical scenario
An API returns mixed values; you need to detect primitives vs objects before cloning or updating state.

Common pitfalls

  • Assuming typeof null is "object" for valid checks.
  • Treating arrays as plain objects without Array.isArray.
  • Mutating objects when you meant to copy.
Trade-off or test tip
Primitives are predictable, objects are flexible but mutable. Test typeof, Array.isArray, and reference equality.

Still so complicated?

Think of primitives as single paper notes — once written, they can’t be changed. Objects are like folders — you can add, remove, or edit their contents anytime.

Summary
  • Primitive types (7): Number, String, Boolean, Undefined, Null, Symbol, BigInt.
  • Non-primitive type (1): Object.

Everything else in JavaScript (arrays, functions, dates, regex, etc.) is an object.

Similar questions
Guides
Preparing for interviews?

Use this as one explanation rep, then continue with the JavaScript interview questions cluster or a guided prep path.