Skip to main content

JavaScript Data Types

In JavaScript, data types serve as the building blocks for variable assignments and manipulations within a program. These data types can be broadly categorized into two groups: primitive data types and object data types.

Primitive Data Types:

  1. String:

    • The string data type is employed to represent textual information within the program.
    let name = "John";
  2. Number:

    • The number data type encompasses both integers and floating-point numbers.
    let age = 25;
    let height = 1.75;
  3. Boolean:

    • Booleans represent logical values, taking on either true or false.
    let isStudent = true;
  4. Undefined:

    • The undefined data type represents variables that have been declared but not assigned any value.
    let city;
  5. Null:

    • Null signifies the intentional absence of any object value.
    let result = null;
  6. Symbol:

    • Symbols, introduced in ECMAScript 6, are unique and immutable primitive values.
    let id = Symbol("uniqueId");

Object Data Types:

  1. Object:

    • Objects represent a collection of key-value pairs, allowing the grouping of related information.
    let person = { name: "Alice", age: 30 };
  2. Array:

    • Arrays are ordered collections of values, enabling the storage and manipulation of multiple items.
    let numbers = [1, 2, 3, 4, 5];
  3. Function:

    • Functions serve as reusable blocks of code, encapsulating specific logic for execution.
    function greet(name) {
    console.log("Hello, " + name + "!");
    }
  4. Date:

    • The Date object is used for representing date and time values within the program.
    let today = new Date();
  5. RegExp:

    • Regular expressions, represented by the RegExp object, enable pattern matching within strings.
    let pattern = /[a-z]+/;