In earlier tutorial, we went through Variables in JavaScript. Every variable in JavaScript is of certain data type, be it a number or a string, etc. There are 8 data types in JavaScript namely
Let’s go through each one of them with their definition and examples
This datatype represents a number which can be both an Integer or a floating point number.
E.g.
let num=2
console.log(typeof num) //number
The Number datatype can only accommodate numbers greater than -(253-1) and less than (253-1). If there is a need to use a larger datatype to accommodate numbers beyond this range, we can use BigInt datatype. It is initialized by appending ‘n’ at the end of the number.
E.g.
let bigNum=3232323232323232222222222222222222222222222n
console.log(typeof bigNum) // bigint
We use String data type to store a textual data. A string variable can be initialized by adding quotes around the text. These quote can be double quotes (“text”) or single quotes (‘text’) or backtick quotes (`text`).
E.g.
let address=”10 downing street”
console.log(typeof address) // string
Boolean data type is used to represent variables having only two possible values i.e. either true
or false
.
E.g.
let isAdmin=false
console.log(typeof isAdmin) //boolean
let isBoss=true
console.log(typeof isBoss) //boolean
Null datatype refers to a variable which is non-existent or empty.
E.g.
let name=null;
console.log(name) //null
console.log(typeof name) //object
Undefined refers to the variables whose value is unknown or not yet defined.
E.g.
let name;
console.log(name) //undefined
This datatype is used to refer to variables which is an Object.
This datatype is used when we want to create unique identifiers for the objects.
Fully customizable CRM Software for Freelancers and Small Businesses