LearnThatStack Ace your next interview
JavaScript · question
Question 5 of 126

What are the primitive data types in JavaScript?

beginner
← All JavaScript questions
Re-explain

JavaScript has 7 primitive data types. A primitive is a value that is not an object, and it cannot be changed once it is created.

  1. Number, for integers and floating-point numbers.
  2. String, for text.
  3. Boolean, which is true or false.
  4. Undefined, the value of a variable that was declared but not assigned.
  5. Null, an intentional absence of value.
  6. Symbol, a unique identifier added in ES6.
  7. BigInt, for integers beyond Number.MAX_SAFE_INTEGER, added in ES2020.

Arrays, functions and every other value are objects. typeof null returns "object", a legacy bug kept for compatibility.

Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

Why there's no diagram: “”

The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓

The diagram below the answer is the concept . Jump to it ↓

Tailored explanation · switch back to · ·
What should the new diagram focus on?
Guided practice for JavaScript One question at a time. Answer out loud, get graded, see what you missed.
How well did you know this?
AI:

Saved in this browser - sign in to keep your review list.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Interview lens How interviewers actually use this question

Likely follow-ups

  • Why does typeof null return "object", and how do you check for null reliably? Call it a legacy bug kept for compatibility, then show value === null as the check, since typeof can't tell null from an object.
  • If primitives are immutable, how can you call "hello".toUpperCase()? JavaScript wraps the string in a temporary String object to find the method. The method returns a new string and the original stays the same.
  • How do primitives and objects behave differently when you assign them or pass them to a function? Primitives are copied by value. An object variable holds a reference, so a change made through one variable shows up through the other.
  • What is the difference between null and undefined, and when would you use each one? undefined is the default for a missing value, null is set on purpose. Mention that null == undefined is true while null === undefined is false.
  • When would you reach for BigInt, and what happens if you add a BigInt to a Number? Integers past Number.MAX_SAFE_INTEGER, like large IDs. Mixing the two in arithmetic throws a TypeError, so convert one side explicitly.

What you can say

  1. JavaScript has seven primitive types, and a primitive is a value that isn't an object and can't be changed once it exists.
  2. Number covers both integers and decimals, String is text, and Boolean is true or false.
  3. Undefined is what a variable holds when it's declared but never assigned, while null is an absence of value you set on purpose.
  4. Symbol came in ES6 and gives you a unique identifier, and BigInt came in ES2020 for integers beyond Number.MAX_SAFE_INTEGER.
  5. Everything else is an object, and that includes arrays and functions.
  6. One trap I'd point out is that typeof null returns "object", a legacy bug kept for compatibility, so I check for null with === null instead.

Weak answers to avoid

  • Counts arrays or functions as primitives Arrays and functions are objects. Say that anything outside the seven primitives is an object, even though typeof reports "function" for functions.
  • Lists five types and forgets Symbol and BigInt Leaving out the ES6 and ES2020 additions suggests your knowledge is dated. Name all seven and say when the last two were added.
  • Treats null and undefined as the same thing They mean different things. undefined is the default for an unassigned variable, and null is an empty value you assign on purpose.
  • Says null is an object because typeof says so typeof null returning "object" is a legacy bug. null is a primitive, and the reliable check is value === null.
Interview lens

Likely follow-ups, what you can say, and the weak answers to avoid.

Sign in free to open it Free account - the lens opens as soon as you're back.

Want a quick review of the fundamentals? See the JavaScript cheatsheet.

← Back to all JavaScript questions
Pro · $10/mo

110 of 126 JavaScript answers are in Pro.

Full answers, code samples, and AI explanations that go simpler or deeper. Cancel anytime.

  • Full answers + code
  • AI explanations, simpler or deeper
  • 1,000 AI credits / month
  • Cancel anytime