agyanadda@gmail.com

JS Data Types

JavaScript Basics 1 min read Updated Dec 1, 2026 Topic 6 of 38

Every value in JavaScript has a type.

Primitive types

Type Example
string 'Hello', "Hi"
number 42, 3.14
boolean true, false
undefined a variable with no value yet
null an intentional "empty" value
bigint 9007199254740993n
symbol a unique identifier

Objects

Objects { }, arrays [ ] and functions are object types.

typeof

typeof tells you the type: typeof 42 gives "number".

JavaScript is dynamically typed: the same variable can hold a number now and a string later.

Example

Example — Checking types with typeof HTML
<pre id="out"></pre>

<script>
  const values = ['Hello', 42, true, undefined, null, [1, 2], { a: 1 }];
  let text = '';
  for (const v of values) {
    text += JSON.stringify(v) + ' → ' + typeof v + '\n';
  }
  document.getElementById('out').textContent = text;
</script>

Note: typeof null is "object" — a famous old JavaScript quirk.

Try it Now »

Test Yourself With Exercises

Exercise 1 Multiple Choice

What does typeof 'hello' return?

Exercise 2 True / False

true and false are boolean values.

Exercise 3 Fill in the Blank

A variable declared without a value has the value ___.

Frequently Asked Questions

undefined means a value was never assigned. null is a value you set on purpose to mean "nothing".