Data types in JavaScript

1) INTRODUCTION :- Data type defines the type of data is being hold by object. Mostly all the data types are common in all the languages. Some common data types are integer, string, Boolean, null. There are some additional data types in JavaScript that are as object, undefined.

You will learn :-

1) Types of data type
2) primitive data types
3) non-primitive data types
4) difference between all the data types.

Prerequisites:- basics of programming.

Data type:- Data type provides the information about the value which is being stored in the variable.

There are two types of data type in JavaScript.

1) Primitive data type
2) Non-primitive data type

1) Primitive Data types: — Primitive data types are the primary data types. For example Number, String, Boolean
There are 5 primitive data types
a) String
b) Number
c) Boolean
d) null
e) undefined

Let’s discuss all of them one by one.

a) String: — String data contains series of characters enclosed in double quotes (“”) Or single quotes(‘’).
Now we can use back ticks as well for dynamically assigning values in the string.

EXAMPLE:-

Output:-

In the above example, all the three variables are string. name variable is enclosed in “” double quotes, country variable is enclosed in ‘’ single quote and then description which is enclosed in `` back ticks where we assigning values dynamically.

b) Number :- Number data type contains number values in the variable.
Number values can be in decimal as well. There are methods which can convert the decimal to integer or integer to decimal.

EXAMPLE:-

Output:-

In the above example, we have taken three variables as hindi,english,Javascript and assigned 64, 64, 61 respectively. Then we have taken avg as variable and did mathematical operations and assigned average of three subjects .

c) Boolean:- Boolean data type contains true or false value in the object.

EXAMPLE:-

Output:-

In the above example we have taken boolFlag and assigned value as true and then we have printed the data type of the variable. Then boolFlag value changed to false and again we have printed it’s data type.

d) undefined :- Any object which is not defined with the value will have undefined as data type and it’s value will also be as undefined.

EXAMPLE:-

Output:-

In the above example value is not assigned to the name variable while declaring it. And then after declaring the variable it’s data type is getting printed.

Non-primitive Data Types:- These types are collection data types where multiple primitive data type values are stored in one variable.
Below are the two primitive data types.

1) Array
2) Object

1) Array:- Array data type stores multiple values in single variable. Values can be accessed through their index numbers. Index number always starts from 0. It means that the first value will be at the 0th index number in the array.

2) Object:- Object data type stores data in the key value pair. There is one constraint that the key should of type String.

EXAMPLE :-

Output:-

In the above example “countries” variable has been taken and array of string values are assigned to it and then we have printed it data type. Output is showing object for array it means array is also of type object and object where data is stored in Key-value pair is also of type object.

BHAGAVAD GITA:- The song of God

Sattva binds one to material happiness; rajas conditions the soul toward actions; and tamas clouds wisdom and binds one to delusion.

I am a Software Developer in MNC company and I do Freelancing and blogging as well.