CodeBlanks Logo Icon CodeBlanks

First data types

JavaScript course · Beginner · Lesson 3/133

Learn the basic data types number, string and boolean and the primitive concept.

What is a data type?

A value's type tells what kind of information it is: a number, a piece of text, or true versus false. The three core types you use most in JavaScript are number, string and boolean.

These three are known as primitive types; each is a single, immutable unit. let yas = 25; is a number, let ad = "Alex"; is a string, let aktif = true; is a boolean. The type shows from the shape of the value you write.

The boolean type

A boolean takes only two values: true or false. It is used to hold whether something is on/off, present/absent, yes/no.

For example let loggedIn = true; means the user is signed in, while let stokta = false; means a product is out of stock. true and false are written in lowercase, without quotes. They are reserved keywords in JavaScript.

What is each type used for?

The number type holds numeric information like age, price, temperature or score. The string type holds text like a name, an email, a city or a description. The boolean type holds whether a state is on/off or true/false.

The type choice keeps code meaningful. To store a friend's age you write let yas = 25; (number). To store their email you write let eposta = "alex@mail.com"; (string). To ask whether they are an active user you write let aktif = true; (boolean).

Exercise Declare variables of three types and print them

Declare one number, one string and one boolean variable. Then print all of them with console.log.

Show example solution
let yas = 25;
let sehir = "Berlin";
let aktif = true;
console.log(yas, sehir, aktif);

Test yourself

  1. Which of these is a value of type number?

    • "hello"
    • true
    • 42
    • "2024"
    Show answer

    42 — Correct. 42 is written without quotes, so its type is number.

  2. Define a string value

    let sehir = ____;
    Show answer
    let sehir = "Berlin";
  3. Match each value to its type

    42
    number
    "hello"
    string
    true
    boolean (true)
    false
    boolean (false)

All lessons in Beginner