DeployU
Interviews / Frontend Engineering / What are the different data types in JavaScript?

What are the different data types in JavaScript?

conceptual Core Concepts Interactive Quiz Code Examples

The Scenario

You are a frontend engineer at a social media company. You are writing a new feature that needs to work with a variety of different data types.

The Challenge

Explain the different data types in JavaScript. What are the primitive data types, and what are the non-primitive data types?

Wrong Approach

A junior engineer might not be aware of all the different data types in JavaScript. They might also not be aware of the difference between primitive and non-primitive data types.

Right Approach

A senior engineer would be able to provide a detailed explanation of all the different data types in JavaScript. They would also be able to explain the difference between primitive and non-primitive data types.

Step 1: Understand the Primitive Data Types

Data TypeDescription
stringA sequence of characters.
numberA number, including integers and floating-point numbers.
booleanA boolean value, either true or false.
nullA special value that represents the intentional absence of any object value.
undefinedA special value that represents a variable that has been declared but has not yet been assigned a value.
symbolA unique and immutable value that can be used as the key of an object property.
bigintA number that can represent integers of arbitrary precision.

Step 2: Understand the Non-Primitive Data Type

Data TypeDescription
objectA collection of key-value pairs.

Arrays and functions are also objects in JavaScript.

Step 3: The typeof Operator

You can use the typeof operator to check the type of a variable.

typeof "hello" // "string"
typeof 123 // "number"
typeof true // "boolean"
typeof undefined // "undefined"
typeof null // "object" (this is a well-known bug in JavaScript)
typeof Symbol() // "symbol"
typeof 123n // "bigint"
typeof {} // "object"

Practice Question

What will `typeof null` return?