4javascriptdata

Understanding Data Types in JavaScript

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!

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

Note: We aim to make learning easier by sharing top-quality tutorials, but please remember that tutorials may not be 100% accurate, as occasional mistakes can happen. Once you've mastered the language, we highly recommend consulting the official documentation to stay updated with the latest changes. If you spot any errors, please feel free to report them to help us improve.

top-home