One of the most important component of a programming language is its datatypes. They can be looked upon as a building block of any programming language. In this article we will play around with datatypes in JS and explore more about it!
Primitives are immutable.There are 7 different Primitives
Objects are nothing but collection of data in form of key value pairs.
The typeof operator helps us to find the type of any unevaluated operand. For eg,
BigInt is a datatype which deals with operations on huge value of integer numbers. BigInt allows to work with numbers beyond the limit of Number primitive.
BigInt is represented by suffix n.
Often while writting programs we need to convert data from one form to another. Here are few conversion methods.
1. Number to String
There are 3 ways to convert a number to string
consider, const no=10;
2.String to Number
There are 3 ways to convert a string to number
consider, const str='10';
Common Methods on Number object
Number.isInteger(3.5); //false Number.parseInt('5.8'); //5 Number.parseFloat('5.86'); //5.86 Number.isNaN(NaN); //true Number.isNaN('text'); //false 10.567.toFixed(2) //10.57 10.567.toPrecision('3'); //10.6
NaN is a special type of number which results by invalid mathematical operations. For eg subtracting a string and number.
Methods on Math object.
Math.abs(-5); //5 Math.floor(1.6) //1 Math.ceil(3.5) //4 Math.round(3.67) //4 Math.max(-5,3,8) //8 Math.min(-5,3,8) //-5 Math.sqrt(64) //8 Math.pow(5,3) //125 Math.trunc(-6.3) //-6
Symbol represents a unique identifier.Symbols are used to identify object properties and to add unique property keys to an object.