Skip to content

[Javascript] Data Types and Object

Posted on:September 26, 2022 at 12:13 PM

A data type is a classification of data which tells the compiler or interpreter how the programmer intends to use the data.

A value in JavaScript is always of a certain type. For example, a string or a number.

There are 8 basic data types in JavaScript.

Seven primitive data types:

And one non-primitive data type:

We will go throught all of them in this article. Let’s step!

Table of contents

Open Table of contents

What is typeof operator?

JavaScript provides a typeof operator that can examine a value and tell you what type it is.

let transform;
typeof transform; // "undefined"

transform = "hello there";
typeof transform; // "string"

transform = 22;
typeof transform; // "number"

transform = false;
typeof transform; // "boolean"

transform = undefined;
typeof transform; // "undefined"

transform = null;
typeof transform; // "object" -- so confusing

transform = { clothes: "red" };
typeof transform; // "object"

transform = ["clothes", "hair", "materials"];
typeof transform; // "object"

transform = Symbol("Any thing here");
typeof transform; // "symbol"

What is the object type?

The object type refers to a compound value where you can set properties (named locations) that each hold their own values of any type.