This guide will introduce you to the different data types in JavaScript and how they’re used. Understanding data types is essential for working with variables in JavaScript. Practice creating different types to see how they work!
Understanding Data Types in JavaScript
JavaScript Data Types
Data types describe the kind of data stored in a variable. Here are some common data types in JavaScript:
1. Number
Used for numbers, both whole and decimal.
let score = 100;
let price = 19.99;
2. String
Strings are text wrapped in quotes.
let greeting = "Hello, world!";
let favoriteColor = 'blue';
3. Boolean
Boolean values are either true
or false
, perfect for yes/no questions.
let isSunny = true;
let isNight = false;
4. Null
null
represents “no value.” It’s intentional, meaning the variable is empty on purpose.
let result = null;
5. Undefined
If a variable has been declared but not assigned a value, it is undefined
.
let futureValue;
console.log(futureValue); // Output: undefined