Before We Begin

Before learning how to write and use functions, we first need to understand data types.

A program works by processing data, and functions receive that data, perform operations on it, and return results.

For that reason, it’s important to know what kinds of data you’re working with.

Numbers

The simplest data type is the Number.

Numbers are used to store values such as ages, prices, scores, and any other numeric data.

var age = 20;

Strings

If you want to store text, you use the String data type.

Strings can be written using either double quotes (" ") or single quotes (' ').

var word = "Hello";
var word2 = "Hello";

Both forms are valid in JavaScript.

Boolean

A Boolean can have only two possible values:

  • true
  • false

Booleans are commonly used to represent conditions, such as whether something is enabled, completed, or available.

var isHard = false;
var isEasy = true;

Arrays

Sometimes you need to store multiple values instead of just one.

That’s where an Array becomes useful.

An array can contain values of any data type, and it can even mix different types together.

var myArray = ["Hello", 4, true];

Arrays can also store values of the same type.

var myWords = ["Word1", "Word2", "Word3", "Word4"];
var myNumbers = [1, 2, 5, 10];
var myLevels = [true, true, false, true];

Are There More Data Types?

Yes.

JavaScript includes several additional data types, such as:

  • null
  • undefined
  • object

We’ll cover these in future lessons.

For now, focus on the four basic types you’ll use most often.

What’s Next?

In the upcoming lessons, you’ll learn how functions receive these data types, process them, and produce new results.

Key Takeaways

  • Every value in JavaScript has a data type.
  • The basic data types are:
    • Number for numbers.
    • String for text.
    • Boolean for true/false values.
    • Array for storing multiple values.
  • You’ll learn additional data types like null, undefined, and object later.