Skip to content

Primitive data types in JavaScript

  • by

JavaScript Primitive data types represent a single value and are not an object. It includes Number, String, Boolean, Undefined, Null, Symbol, etc.

List of primitive data types in JS.

  1. String: represents a sequence of characters, enclosed in quotes (either single or double).
  2. Number: represents both integer and floating-point numbers.
  3. Boolean: represents a logical value of either true or false.
  4. Undefined: represents a variable that has been declared but has not been assigned a value. Example: let x;
  5. Null: represents a variable that has been explicitly assigned the value of null. Example: let y = null;
  6. Symbol: represents a unique identifier that can be used as the key of an object property. Example: const id = Symbol('id');.
  7. bigint: BigInt is a numeric data type in JavaScript that was introduced in ECMAScript 2020. It is used to represent integers that are larger than the maximum safe integer that can be represented by the Number data type, which is 2^53 – 1 (or 9,007,199,254,740,991).

Primitive data types in JavaScript example

Simple example code.

<!DOCTYPE html>
    let message = "Hello, World!"; // String

    let age = 42; // Number

    let isStudent = true; // Boolean

    let x; // Undefined

    let n = null; // Null

    const id = Symbol('id'); // Symbol



Primitive data types in JavaScript

These data types are called “primitive” because they are not objects and have no methods or properties of their own. However, JavaScript automatically converts primitive values to objects when necessary, using a process called “boxing”.

Comment if you have any doubts or suggestions on this Js data type topic.

Note: The All JS Examples codes are tested on the Firefox browser and the Chrome browser.

OS: Windows 10

Code: HTML 5 Version

Leave a Reply

Discover more from Tutorial

Subscribe now to keep reading and get access to the full archive.

Continue reading