Data types in Javascript



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

  1. Number
  2. BigInt
  3. String
  4. Boolean
  5. Null
  6. Undefined
  7. Objects
  8. Symbols

Javascript Image

Let’s go through each one of them with their definition and examples


1. Number

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


2. BigInt

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


3. String

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


4. Boolean

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


5. Null

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


6. undefined

Undefined refers to the variables whose value is unknown or not yet defined.

E.g.
let name;
console.log(name) //undefined


7. Object

This datatype is used to refer to variables which is an Object.


8. Symbol

This datatype is used when we want to create unique identifiers for the objects.

Follow Me on Social Media

Advertisement
FREE Sales CRM Software

Fully customizable CRM Software for Freelancers and Small Businesses

Signup for Free

Sign up for DigitalOcean Cloud

Get FREE $200 credits, deploy your hobby projects for Free

DigitalOcean Referral Badge
Sign up for Hostinger Cloud or VPS plans and get upto 20% Discount