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.