JavaScript Data Types

Strings, numbers, booleans, objects and more.

✍️ 3 exercises + code challenge in this lesson

JavaScript has 8 data types:

  • String: text, "Hello"
  • Number: integers and decimals, 42, 3.14
  • BigInt: very large integers, 9007199254740993n
  • Boolean: true or false
  • Undefined: a variable with no value
  • Null: intentionally "nothing"
  • Symbol: a unique identifier
  • Object: collections such as objects, arrays and dates

JavaScript is dynamically typed: the same variable can hold different types. Use typeof to check a type.

Key Takeaways: JavaScript Data Types

Mastering JavaScript Data Types helps you write clean and reliable JavaScript code. Follow standard conventions, test edge cases, and keep logic simple. Try running the code example below and complete the exercises to build confidence.

JavaScript Data Types Code Example

JavaScript
<pre id="out"></pre>
<script>
const log = (...a) => document.getElementById("out").textContent += a.join(" ") + "\n";
let value;
log(typeof value);        // undefined
value = "text";   log(typeof value);
value = 42;       log(typeof value);
value = true;     log(typeof value);
value = { a: 1 }; log(typeof value);
value = [1, 2];   log(typeof value, "(arrays are objects)");
value = null;     log(typeof value, "(a famous JavaScript quirk)");
log(typeof 10n);
</script>
Free sign-in required · Google login available

JavaScript Data Types Practice Exercises

Check what you learned in “JavaScript Data Types”.

/ 3 solved
Fill in the blank

Find out the type of a value.

 "hello"   // "string"
✓ Correct! Not quite. Try again.
Multiple choice

What does typeof null return?

✓ Correct! Not quite. Try again.

This is a well-known historical quirk of JavaScript.

Code challenge

Log the type of the value 42.

Write the code in the live editor. Your answer is checked automatically.

Free sign-in required · Google login available

to save your exercise progress.
Finished this lesson?
Mark it complete to track your progress.

Stuck on something?

Ask the community in the CodesInTech forum.

Need a developer?

Learning on your own is great — and when you need professional help, our team builds custom software, websites and mobile apps for clients worldwide.

Explore Our Services