Skip to content

Update JS data types lesson #63166

@jdwilkin4

Description

@jdwilkin4

I removed the console.log() since it wasn't explained in the lesson and ultimately not needed here.
I also updated the Symbol example.

Here is the new version

---
id: 672d496eca926b5df8176a67
title: What Is a Data Type, and What Are the Different Data Types in JavaScript?
challengeType: 19
dashedName: what-is-a-data-type
---

# --description--

In JavaScript, a data type refers to the kind of value a variable holds.

A variable is a named container that stores a value of a specific data type, allowing you to reference and manipulate it throughout your code. Data types help the program understand the kind of data it's working with, whether it's a number, text, or something else.

JavaScript has several basic data types that you'll use in your programs. We'll explore each data type in greater detail in future lessons. For now, here is a brief introduction of the different data types in JavaScript.

The first data type we will look at is the `Number` type.

A `Number` represents both integers and floating-point values. Examples of integers include `7`, `19`, and `90`. Examples of floating point numbers include `3.14` and `5.2`. A floating point number is a number with a decimal point.

The next data type is a `String`.

A `String` is a sequence of characters, or text, enclosed in quotes. Here are two examples:

```md
"Hello, world"
```

```md
'JavaScript'
```

Another data type used in JavaScript is the `Boolean` type.

A `Boolean` represents one of two possible values: `true` or `false`. You can use a boolean to check if a page is loading, or if a user is logged in or not.

The next two data types used in JavaScript are `undefined` and `null`.

`undefined` means a variable has been declared but hasn't been given a value yet. `null` means the variable has been intentionally set to "nothing" and does not hold any value. We will explore more on how this works in future lessons.

The next data type we will look at is the `Object` type.

An `Object` is a more complex data type that can hold collections of key-value pairs. Let's break this down. The key (also called a property name), is like a label for the data, whereas the value, is the actual data you want to store. Here is an example:

```js
let book = {
  title: "The Great Gatsby",
  author: "F. Scott Fitzgerald",
  year: 1925
};
```

In this object, `title`, `author`, and `year` are the keys (or property names). `The Great Gatsby`, `F. Scott Fitzgerald`, and `1925` are the corresponding values.

Each key-value pair in an object is called a property. So we can say that this book object has three properties. This is just a basic introduction to objects and their properties. In future lessons, we'll go deeper into more advanced concepts.

The last two data types are the `Symbol` and `BigInt` data types.

A `Symbol` is a special type of value in JavaScript that is always unique and cannot be changed. It's often used to create unique labels or identifiers for properties:

```js
Symbol('mySymbol');
```

`BigInt` is used for very large numbers that exceed the limit of the `Number` type:

```js
1234567890123456789012345678901234567890n;
```

In this example, we create a `BigInt` by adding `n` at the end of a very large number.

`Symbol` and `BigInt` are two types that are less commonly used, but they are still important to know about.

Understanding these data types helps you handle and work with various kinds of data in your programs, as each type has its own characteristics and behaviors.

# --questions--

## --text--

Which of the following is a string data type?

## --answers--

`"Hello!"`

---

`42`

### --feedback--

Think about which data type is enclosed in quotes.

---

`false`

### --feedback--

Think about which data type is enclosed in quotes.

---

`null`

### --feedback--

Think about which data type is enclosed in quotes.

## --video-solution--

1

## --text--

What data type represents a value that is either `true` or `false`?

## --answers--

`Number`

### --feedback--

This data type is often used in logical statements.

---

`String`

### --feedback--

This data type is often used in logical statements.

---

`Boolean`

---

`Undefined`

### --feedback--

This data type is often used in logical statements.

## --video-solution--

3

## --text--

If a variable has been declared but not assigned a value, what is its data type?

## --answers--

`String`

### --feedback--

This data type represents an unassigned variable.

---

`Number`

### --feedback--

This data type represents an unassigned variable.

---

`Undefined`

---

`Null`

### --feedback--

This data type represents an unassigned variable.

## --video-solution--

3

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedOpen for all. You do not need permission to work on these.scope: curriculumLessons, Challenges, Projects and other Curricular Content in curriculum directory.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions