CodeBlanks Logo Icon CodeBlanks

Primitive types

Learn the primitive types string, number, boolean, null, undefined.

Primitive types

In JavaScript, primitive types are the most basic data types: number, string, boolean, null and undefined. They hold a single value and are not objects.

number holds both integers and decimals. string holds text. boolean is only true or false.

null means 'intentionally empty', undefined means 'value not yet assigned'. They are different things.

Five primitive types

Let us briefly meet each of the five primitives:

  • number: 42, 3.14
  • string: 'hello', "world"
  • boolean: true, false
  • null: intentionally empty value
  • undefined: not yet assigned value

We will see these in detail later. For now, knowing all five is enough.

Practice Print three different primitives

Declare three variables: name string 'Alex', count number 7, active boolean true. Call console.log with each.

Starter code

index.js
// Declare name, count and active variables
// Log all three

Sample solution

index.js
const name = "Alex";
const count = 7;
const active = true;
console.log(name);
console.log(count);
console.log(active);

Expected output

Alex
7
true

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 Which one is a primitive type?

  • Array
  • Number Correct answer
  • Object
  • Function

Explanation: number is a primitive type.

2 boolean example

Question
const isOpen = ____;
Answer
const isOpen = true;

Explanation: yes or 1 are not booleans.

3 Match the primitive types

Term Meaning
number Number
string Text
boolean Logical
undefined Not defined

All lessons in Beginner