Datatypes in Javascript

Datatypes in Javascript

In this article we will discuss about the datatypes in javascript

JavaScript has several built-in data types, which can be broadly categorized into two main categories: primitive data types and non-primitive (or reference) data types.

Primitive Data Types: These are the basic building blocks of data manipulation in JavaScript. They are immutable (cannot be changed) and are directly operated upon.

  • Number: Represents both integer and floating-point numbers. Example: let num = 10;

  • String: Represents a sequence of characters, enclosed within single (' '), double (" "), or backticks (` `) quotes. Example: let str = 'Hello';

  • Boolean: Represents a logical value, either true or false. Example: let isTrue = true;

  • Undefined: Represents a variable that has been declared but not assigned any value yet. Example: let variable;

  • Null: Represents an intentional absence of any value. Example: let absent = null;

  • Symbol: Introduced in ECMAScript 6, represents a unique and immutable value that may be used as the key of an Object property. Example: const sym = Symbol('description');

  • BigInt: Introduced in ECMAScript 2020, represents whole numbers larger than 253 - 1 or less than -253 + 1. Example: const bigNum = 123n;

Non-Primitive (Reference) Data Types: These are objects that are accessed by reference and are mutable (can be changed).

  • Object: Represents a collection of key-value pairs. Example: let obj = { key: 'value' };

  • Array: Represents a collection of elements, ordered and accessible by indices. Example: let arr = [1, 2, 3];

  • Function: Represents a callable object. Example: function myFunction() { /* function body */ }

  • Date: Represents a date and time. Example: let date = new Date();