Javascript

Data Types in JavaScript

We have two major categories of data types in JavaScript:

Primitive Data Types :

•Number

•bigInt

•boolean

•string

•undefined

•null

•symbol

Non-Primitive or Referenced Data Types

Objects (functions, arrays, String, Date, Math etc)

Number

•Numbers between -(2^53 − 1) and 2^53 − 1

•Integer or floating point

•Have additional 3 symbolic values :  +Infinity, -Infinity, NaN

• Number.MAX_VALUE 

•Number.MIN_VALUE

•Number.isSafeInteger()

•Number.MAX_SAFE_INTEGER

•Number.MIN_SAFE_INTEGER

•0 and -0

BigInt

•The BigInt type is a numeric primitive in JavaScript that can represent integers with arbitrary precision.

•BigInt is created by appending n to end or by constructor approach.

Examples:

var num1 = 99984293840n;

var num2 = BigInt(123456);

Boolean

•Boolean is a logical data type that can have only the values true or false.

• Generally used in  conditional statements to decide which section of code to be executed.

Examples:

var check = true;

  var check = false;

String

•To represent textual data. •

•Anything between double quote(“ ”), single quote(‘’) and backtick(“) is a String

•The length of a String is the number of elements in it.

Examples:

var test = ‘dummy’

  var test = “23”

  var test3 = `backtick`

Undefined

•A variable that has not been assigned a value is of type undefined. •

•JavaScript automatically assign it with undefined.

•Undefined is not a reserved keyword. Its bad practice to use identifiers with name undefined.

Examples:

  var test ; // initialized with undefined

  var test1 = undefined.

Null

•Represent ‘empty’ or ‘nothing’ or ‘unknown’

•Usually represents intentional absence of any object value.

Examples:

var test = null;

Symbol

•Symbol is a primitive data type , that can be created using factory function symbol

•It returns a unique symbol

•Used to add unique property keys to object.

Examples:

var test = Symbol();

Object

•Object is used to store key value pairs in JavaScript.

•It contains named values called properties and methods.

•Objects can be created in 3 ways :

• Using Object literals.

•Using Object Constructors.

•Using Object.create() method.

•Use delete operator to delete a property or method of object.

•Fetch all keys of object using  Object.keys().

Fore more detailed explaiantion with the help of examples, Please check below video:

Let me know in the comments section of video, if you have any questions or doubts.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s