Data Types In JavaScript

JavaScript Data Types

  • String
  • Number
  • Bigint
  • Boolean
  • Undefined
  • Null
  • Symbol
  • Object

JavaScript Data Types

1. String 

let color = "Red";
let name = "Chintan";
let city = "Mumbai";

2. Number 

let width = 10.5;
let height = 8;
let length = 45.03;

3. Bigint 

let x = 14537876623897006549000000; // big number
let bin = 0245008666096600BnwY; // binary data
let hex = 9999999999999f999999999945000000000bj; 

4. Boolean 

let abc = true;
let z = false;

5. Undefined 

let a ; // a data type whose variable is not initialized (Value is undefined)
let xyz; // value is undefined

6. Null 

let a = null ; // assign value is null

7. Symbol 

const value = Symbol('hello'); // Symbols are immutable and are unique. 

8. Object 

const personData = {firstName:"Deo",lastName:"John"};

JavaScript Most Important Concepts of Data Types

1. When adding a number and string, JavaScript will treat the number as a string.

let a = 16 + "Books";
// Result : 16Books

let x = "Books" + 89;
// Result : Books89

2. When sequences first added number then we get a different result

let z = 5 + 20 + "Jobs";
// Result : 25Jobs

3. When sequences first added string then we get different result

let x = "Cars" + 15 + 8 ;
// Result : Cars158

4. When comparing two values, we get a different result in boolean value 

let a = 4 ;
let b = 5 ;
let c = 4 ;

a==b // false
a==c // true
b==c // false
let x = "3";
let y = 3;

x==y // true
x===y // false (=== is also check data type of both values)


Similar Articles