Data types in javascript

Javascript is a dynamically typed language we don't need to specify the data type before declaring a variable.

5 primitive data types in Javascript:

  • String
    let name = "tom"
    
  • Number
    let num = 1;
    let sum = 2.2
    
  • Boolean
    let isEvenNumber = true
    let isOddNumber = false
    
  • Undefined
    let name;
    console.log(name)   // undefined
    

    By default undefined is assigned to 'let' and 'var'.
  • Null let name = null;

Two non primitive data types are:

  • Object
    let obj = { name: 'tom', age: 5}
    
  • Array
    let names = ['tom', 'jerry']