HomeTutorsContact
JavaScript
How To Check Data Types in JavaScript?
Gulshan Saini
June 20, 2020
1 min

Data types are an important concept in any programming language. They tell us what type of data variable holds. In JavaScript typeof operator can be used to get the data type of any variable.

A variable in JavaScript could hold primitive, object, and function data type. The functions are not data structure however when we evaluate any expression that holds function as it’s value the typeof returns function in return as the data type.

Primitive data types are string, number, bigint, boolean, undefined, and symbol.

On the other side the Object data type includes null, array and any instance created using new keyword like new Object(), new Array(), new Map(), new Set(), new WeakMap(), new WeakSet(), and new Date().

Below are examples of how to check different data types

String

Output

Number

Output

Bigint

A BigInt is created by appending n to the end of an integer literal. BigInts, can operate with numbers beyond the Number.MAX_SAFE_INTEGER i.e. 9007199254740991.

Output

Boolean

Output

undefined

Output

Symbol

Symbol were introduced in ES6 i.e. ECMAScript 2015. A Symbol value represents a unique identifier.

Output

Object

Object Literal

Output

Date instance

Output

null

You would be surprised to know that null is also having data type of object

Output

Arrays

Output

Function

Output


Tags

#javascript
Previous Article
How to disable prettier in VSCode for a specific project?

Subscribe to our newsletter!

We'll send you the best of our blog just once a month. We promise.

Related Posts

How to Get Current Date in Human Readable Form in JavaScript?
October 03, 2020
1 min
© 2020, All Rights Reserved.

Quick Links

Advertise with usContact Us

Social Media