DEV Community

Cover image for JavaScript - Primitive and Non-Primitive Datatypes
Muhib ur Rahman Bakar
Muhib ur Rahman Bakar

Posted on

JavaScript - Primitive and Non-Primitive Datatypes

In JavaScript, there are two main categories of data types: primitive and non-primitive (also called reference).

Primitive data types are simple, immutable values that are stored directly in the memory. There are six primitive data types in JavaScript:

String: A sequence of characters, represented in quotes (single or double). Example: "Hello World"
Number: Numeric values. Can be integers or floating-point values. Example: 42
Boolean: A value that is either true or false. Example: true
Null: A value that represents the absence of a value or object. Example: null
Undefined: A value that indicates a variable has not been assigned a value. Example: undefined
Symbol: A unique, immutable data type that can be used as an identifier for object properties. Example: Symbol("description")

Non-primitive (reference) data types are values that are stored as references in memory. These data types are objects, and they are mutable (can be modified). Here are some examples of non-primitive data types:

Array: An ordered collection of values. Example: [1, 2, 3]
Object: A collection of key-value pairs. Example: {name: "John", age: 30}
Function: A block of code that can be called by name. Example: function greet() { console.log("Hello!") }
Date: A value that represents a specific point in time. Example: new Date()

I hope this helps! Let me know if you have any questions.

Top comments (0)