JavaScript Code

JavaScript Data Types

Data Types

Data types are useful as to how a value should be treated. For example we want JavaScript to handle how two numbers are added, and how two strings are added. This could be possible with the concept of data types.

In JavaScript, we have the following data types.

  • number
  • string
  • boolean
  • object
  • undefined
x = 84;             //number
x = "apple";        //string
x = true;           //boolean
x = {a: 10, b: 20}; //object
x = undefined;      //undefined


number data type is used to hold numeric values. These numeric values can be with a decimal, or without a decimal.

let n = 25;
let pi = 3.14;


String is a sequence of characters. Single quotes are double quotes can be used to enclose the sequence of characters, and define a string literal.

let name = "Apple";
let car = 'TATA XUV 700';


Boolean can have a value of either true or false. true is ON, false if OFF in terms of logic gates.

let name = "Apple";
let car = 'TATA XUV 700';


An object is a collection of name:value pairs.

let myPhone = {name: "Apple", storage: 256; ram: 6};


undefined is the only value for the data type undefined. When a variable is not defined, then the variable is of type undefined.

let idk = undefined;