Microbit JavaScript
Intermediate
60 mins
Teacher/Student led
+320 XP
What you need:
Chromebook/Laptop/PC

JavaScript Data Types

In this lesson, you'll explore the various data types in JavaScript, including strings, numbers, booleans, arrays, objects, and undefined values. Follow step-by-step examples and exercises to understand how to declare and use these data types effectively in your code.

Teacher Class Feed

Load previous activity

    1 - JavaScript Data Types

    JavaScript variables can store many different data types. A "data type" means the type that the data is. For example a person's name is a string data type (text) and their age is a number data type.

    let firstName = "Marcus"    // string
    let lastName = "Jones"      // string
    let age = 17                // number
    
    In programming, text values are called text strings.

    Strings are written inside double or single quotes. Numbers are written without quotes. If you put a number in quotes, it will be treated as a text string.

    let age = "Fifteen" // string
    let age = "15"      // string
    let age = 15        // number
    

    2 - JavaScript Strings

    A string (or a text string) is a series of characters like "Samuel O'Leary". Strings are written with quotes. You can use single or double quotes.

    let country1 = "USA"    // double quotes
    let country2 = 'Japan'  // single quotes

    You can use quotes inside a string, as long as they don't match the quotes surrounding the string.

    let sentence1 = "Dave O'Leary";           // Single quote inside double quotes
    let sentence2 = "He is called 'Dave'";    // Single quotes inside double quotes
    let sentence3 = 'He is called "Dave"';    // Double quotes inside single quotes

    3 - JavaScript Numbers

    In JavaScript numbers can be written with or without decimal points.

    let price = 4.99   // a number variable with a decimal point
    let age = 23    // a number variable with no decimal point

    4 - JavaScript Booleans

    A boolean is a value that is either true or false. JavaScript booleans can only be one of two values, true or false.

    let isWearingHat = true;
    let isRaining = false;

    Booleans are often used to test conditions in conditional statements such as if then conditional statements.

    if (isRaining){
        isWearingHat = true;
    }else{
        isWearingHat = false;
    }

    5 - JavaScript Arrays

    JavaScript arrays are used to store multiple values in a single variable.

    JavaScript arrays are written with square brackets [] and the array items are separated by commas , The following code creates an array called 'team', containing three players.

    let team = ["John", "Sarah", "Kyrie"]
    123learn · Online learning platform

    Unlock the full learning experience

    You're previewing this lesson. Get full access to this lesson and hundreds more — each one ready to teach, with interactive activities, printable resources and pupil progress tracking built in.

    Hundreds of curriculum-aligned lessons
    Interactive activities in every lesson
    Printable resources & progress tracking
    Copyright Notice
    This lesson is copyright of Coding Ireland 2017 - 2025. Unauthorised use, copying or distribution is not allowed.
    🍪 Our website uses cookies to make your browsing experience better. By using our website you agree to our use of cookies. Learn more