JavaScript Primitive Types

In JavaScript, primitive types are the basic building blocks of the language. They represent single values and are immutable. Here are the six primary primitive types:

1. String

  • Represents textual data.
  • Enclosed in single quotes ('), double quotes ("), or backticks (`).
  • Example:
    let name = "John";
    

    Try It Now

2. Number

  • Represents both integer and floating-point numbers.
  • Example:
    let age = 25;
    let price = 99.99;
    

    Try It Now

3. Boolean

  • Represents a logical entity with two values: true or false.
  • Example:
    let isAvailable = true;
    

    Try It Now

4. Undefined

  • A variable that has been declared but not assigned a value.
  • Example:
    let x;
    console.log(x); // undefined
    

    Try It Now

5. Null

  • Represents the intentional absence of any object value.
  • Example:
    let y = null;
    

    Try It Now

6. Symbol

  • Represents a unique and immutable identifier.
  • Example:
    let sym = Symbol('unique');
    

    Try It Now

7. BigInt

  • Represents numbers larger than the Number type can safely handle.
  • Example:
    let bigIntValue = 1234567890123456789012345678901234567890n;
    

    Try It Now

Characteristics of Primitive Types:

  • Immutable: Their values cannot be changed once created. Operations on primitive values return new values.
  • Stored by Value: When assigned or passed, they are copied.

Understanding these primitive types is crucial as they form the foundation for working with data in JavaScript.