JS Learning

JavaScript Basics

Lesson Progress0%

Section 2 of 4

Data Types

Data Types

Topic Overview

Take your time to understand each concept. Practice with the examples below!

Every piece of information in JavaScript has a "type" - just like in real life where we have different types of things: numbers, words, yes/no answers, etc.

Here are the main types of data in JavaScript:

  • Number - Any number, whole or decimal
Examples: 42, 3.14, -10, 0
Use for: age, price, score, temperature
  • String - Text wrapped in quotes (single or double)
Examples: "Hello", 'JavaScript', "123" (yes, numbers in quotes are text!)
Use for: names, messages, addresses, any text
  • Boolean - Only two possible values:true or false
Examples: true, false
Use for: yes/no questions, on/off switches, completed/not completed
  • Undefined - A variable that exists but has no value yet
Example: let myVariable; (declared but not assigned)
  • Null - Explicitly saying "this has no value"
Example: let data = null; (intentionally empty)

Why do types matter? JavaScript needs to know what type of data you're working with so it can handle it correctly. You can't do math with words, and you can't capitalize a number!

Ready to practice? Try the exercise below to reinforce your learning!

Try it yourself

Create variables of each data type mentioned above.

Loading...