Microbit JavaScript
40 mins
320 points
What you need:
  • Computer/laptop

JavaScript Data Types

In this lesson we learn about JavaScript Data Types and start coding with them.

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;
    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"]

Join our club 😃

To view the remaining 7 steps and access hundreds of other coding projects please login or create an account.

Copyright Notice
This lesson is copyright of Coding Ireland. 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