DEV Community

Khalil Dev
Khalil Dev

Posted on

Type Conversion In JavaScript

To change the type of a value in JavaScript, it is necessary to perform type conversion, which implies transforming the data type from its original state to a distinct one.

There are two main ways to perform type conversion in JavaScript:

1. Implicit Type Conversion (Type Coercion):
JavaScript automatically performs type conversion in certain situations, such as when using operators or functions with operands of different types.

Implicit conversion to String:
JavaScript implicit type conversion

Implicit conversion to Number:
Implicit conversion to Number

2. Explicit Type Conversion:
You can also perform type conversion explicitly using functions such as parseInt(), parseFloat(), String(), Number(), Boolean(), and toString().

Explicit conversion to Number
Explicit conversion to Number

Explicit conversion to String
Explicit conversion to String

Explicit conversion to Boolean
Explicit conversion to Boolean

Thanks for reading
Please share this piece if its helpful.

Top comments (0)