JavaScript Type Conversion

JavaScript Type Conversion


JavaScript Type Conversion
In this tutorial, you will learn about JavaScript type conversion:-
We can convert one data type to another data type with the help of type conversion in JavaScript.
For Example: String to Number, Number to String, Booleans to Numbers and Numbers to Boolean etc.
There are two types of Type Conversion in JavaScript:
  • Implicit Conversion - automatic type conversion
  • Explicit Conversion - manual type conversion
JavaScript Implicit Conversion
In this certain situation, JavaScript automatically converts one data type to another data type (to the right type).
Example – Implicit Conversion Number:
Output
Example - Implicit Conversion String:
Output
JavaScript Explicit Conversion
We can also convert one data type to another data type as per our need that is called explicit type conversion in JavaScript.
In JavaScript, explicit type conversions are done using built-in methods. 
Example – convert number to string using String() method:
Output
Example - convert number to string using toString() method:
Output