JavaScript Data Types

Data Types

1- primitive datatype

String

// String
    
    const name1 = "John Deo"; 
    // Defined variable name1 and initialized value "John Dev".
    
    console.log(name1); 
    // ("run from",name1 )
    

Output

John Deo
    

Number

// Number
    
    const num1 = 7;  
    // Defined variable num1 and initialized 7 in num1 
    
    const num2 = 3.1415;
    // Defined variable num2 and initialized 3.1415 in num2
    
    const num3 = 89e5;
    // Defined variable num3 and initialized 89e5 in num3 
    
    console.log(num1, num2, num3); 
    // ("run from", num1, num2, num3)
    

Output

7 3.1415 8900000
    

Boolean

// Boolean
    
    const data1 = true;
    // Defined data1 variable and initialized boolean value true  
    
    const data2 = false;
    //Defined data2 variable and initialized boolean value false   
    
    console.log(data1, data2);
    // ("run from", data1, data2)
    

Output

true false
    

Undefined

// Undefined
    
    let undefine;  
    // Defined undefine variable and left as is uninitialzed 
    // without any value
    
    console.log(undefine);
    // ("run from", undefine)
    

Output

true false
    

Null

// Null
    
    const n = null;
    // Defined n variable (special keyword denoting a null value)  
    
    console.log(n); 
    // ("run from", n)
    

Output

null
    

Symbol

// Symbol
    
    let id = Symbol("nehal"); 
    // Symbols are unique and cannot be changed. In JavaScript 
    // ES6 it was introduced as a new primitive data type.
    
    console.log(id);
    

Output

Symbol(nehal)
    

2- Object datatype

Array

// Array
    
    const animal = ["cat", "dog", "goat"];
    //  Defined animal variable and initialized 3 Array value
    
    console.log(animal[1]); 
    // ("run from animal[1] than print is index value 2(dog)
    // and array value(1));
    

Output

dog
    

Object

// Object;
    
    const student = {    
    // Defined student variable 
    
      Name: "Anil Kumar", 
    // Defined object name  
    
      class: 6,   
    // Defined object class      
    
      Roll: 45, 
    // Defined object Roll            
    };
    console.log(student); 
    // ("run from", student than print all object value)  
    

Output

{ Name: 'Anil Kumar', class: 6, Roll: 45 }
    

Date

// Date
    
    let now = Date();
    // Defined now variable and initialized date and 
    // Define value any date month year       
    
    //alert=(now);
    // ("run from", shows current date/time)
    
    console.log(now);  
    

Output

Sat May 17 2025 13:03:32 GMT+0530 (India Standard Time)