DEV Community

Khalil Dev
Khalil Dev

Posted on

JavaScript Data Types

In JavaScript, there are different types of data that can be used to represent different kinds of information. These data types can be broadly categorized into two categories: primitive and object.

Primitive Data Types
In JavaScript, a primitive datatype is a data type that represents a single, immutable value.

There are six primitive datatypes in JavaScript:

1. string
It represents textual data, enclosed with single or double quotes.

2. Number
Number represents numeric data, including integers, decimals. It also represent special values like Infinity and NaN(Not a Number).

3. Boolean
It represents a logical value, which can be either true or false.

4. Null
It represents a special value that signifies the absence of any object value.

5. Undefined
It represents a special value that signifies the absence of a value.

6. Symbol
Symbol represents a unique and immutable data type, which is often used to define object properties that should not be altered.

Primitive Data Types can be declared like below:
JavaScript Primitive Data Type

Object Data Types
An object is a composite data type that represents a collection of related data or functionality. Unlike primitive data types that represent a single value, objects can hold multiple properties and methods, and are used to represent more complex data structures.

There are three types of object.
1. Object
Object represents a collection of related data or functionality, typically defined using object literals, object constructors, or classes.

JavaScript Object

2. Array
Array represents a collection of ordered data, typically defined using array literals or the Array constructor.

JavaScript Array

3. Function
It represents a block of code that can be called or invoked, typically defined using function declarations or function expressions.

JavaScript Function Datatype

4. Date
Date represents a specific point in time, typically defined using the Date constructor or Date.parse method.

JavaScript Date

Summary
There are two main Data Types in JavaScript. Primitives are Number, String, Boolean, Null, Undefined, Symbol. Non-Primitives are Object, Array, Function and Date.

Thanks for reading
Please comments you thoughts and share this piece if its helpful.

Top comments (0)