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;