Start learning free

LESSON 14 OF 671 · VARIABLES

Changing Variable Data Type in JavaScript

Lesson

Note that a variable can store values of different types throught a program. It is not constrained to the data type of the initial value we give it at creation:

let a = "peanut";
console.log(typeof a); // Output: string

a = false;
console.log(typeof a); // Output: boolean

a = 13.7;
console.log(typeof a); // Output: number

Assignment
Follow the Coding Tutorial and let's practice with data types!


Hint
Look at the examples above if you get stuck.


STEP 1 OF 2
    Ctrl + Enter to check