JavaScript Tutorialprovides basic and advanced concepts of C# for beginners and professionals.

Different data types available in JavaScript

Back to: JavaScript Tutorial

In JavaScript, there are several built-in data types, which can be categorized into primitive and non-primitive (reference) types.

1. Primitive Data Types

Primitive types are immutable and are directly assigned by value.

  • String: Represents a sequence of characters. Example:
    
        
    javascript
    let name = "John";
    
        
  • Number: Represents both integer and floating-point numbers. Example:
    
        
    javascript
    let age = 30; let price = 19.99;
    
        
  • BigInt: Used for large integers that are beyond the range of the Number type. Example:
    
        
    javascript
    let bigNumber = 1234567890123456789012345678901234567890n;
    
        
  • Boolean: Represents a value of either true or false. Example:
    
        
    javascript
    let isActive = true;
    
        
  • undefined: Represents a variable that has been declared but not assigned a value. Example:
    
        
    javascript
    let x; console.log(x); // undefined
    
        
  • null: Represents an intentional absence of any object value. Example:
    
        
    javascript
    let person = null;
    
        
  • Symbol: Represents a unique and immutable value, often used as object property keys. Example:
    
        
    javascript
    let id = Symbol("id");
    
        

2. Non-Primitive (Reference) Data Types

Non-primitive types are mutable and assigned by reference.

  • Object: Represents a collection of key-value pairs. Example:
    
        
    javascript
    let person = { name: "Alice", age: 25 };
    
        
  • Array: A special type of object used to store ordered collections. Example:
    
        
    javascript
    let numbers = [1, 2, 3, 4];
    
        
  • Function: Functions are a type of object in JavaScript, and can be assigned to variables, passed as arguments, etc. Example:
    
        
    javascript
    function greet() { console.log("Hello!"); }
    
        

These data types cover the range of types you'll use in JavaScript to handle different kinds of data.

Scroll to Top