Datatypes are of two types:-
1.Primitive Datatype
2.Non-Primitive Datatype
1. PRIMITIVE DATATYPE
Primitive Datatypes specify mainly the sizes and shapes of the variable values. There are 8 primitive datatypes namely:-char, byte, Boolean, int, long, float, short, double.
A. Boolean Type Datatype:-
***OTHER PRIMITIVE DATATYPES IN A CODE SNIPPET :-
2.NON PRIMITIVE DATATYPES:-
Non-Primitive Datatypes are the reference type of data. They are the derived datatypes. They contain collection of datatypes . Object and Array are the two important this type of datatype.
***YOU ALL KNOW ABOUT THE OBJECT AND ARRAY .WE WILL GO THROUGH THIS TOPIC.***
CONVERSION OF DATATYPES:-
IMPLICIT CONVERSION
Implicit Conversion is also known as “TYPE COERCION“. Implicit Conversion is defined as the datatype in which one datatype is converted into another type of datatype without the use of explicit instructions. Mainly, these implicit instructions are seen in the mathematical operations and string concatenations.
THE TYPES OF IMPLICIT CONVERSION ARE:-
1. Implicit Conversion to String
2. Implicit Conversion to Number
3. Implicit Conversion in Comparisons
Note: Using ==
allows type coercion, but ===
(strict comparison) does not perform implicit conversion.
SUMMARY TABLE:
EXPLICIT CONVERSION:-
Explicit Conversion is also known as “Typecasting”. Explicit Conversion is defined as the process in which one data type is converted into the another data type manually.
THE TYPES OF EXPLICIT CONVERSIONS
1. Convert to String
2. Convert to Number
We can convert strings or Booleans to numbers using:
A. Number(value).
B. Parse Int(value) for Integers.
C. Parse Float(value) for decimals.
3. Convert to Boolean
Boolean(value).
4. Convert to Object
JSON. parse() is used to convert the code into object. Use JSON. parse() to convert Json strings into object.