The implicit type casting is the conversion of data type done due to the internal requirement or automatic conversion by the compiler or the interpreter.
To understand the implicit conversion let us consider the example of the boolean values (primitive).
JavaScript expects a boolean value in a conditional expression. So JavaScript will temporarily convert the value in parentheses to a boolean to evaluate the if expression.
val = 1;
if (val) {
console.log( 'yes, val exists' );
}
The values 0, -0, '' (empty string), NaN, undefined, and null, evaluate to false and all other values evaluate to true, even empty arrays and objects.
Implicit conversion with == operator.
Type conversion is also performed when comparing values using the equal (==) and not equal (!=) operators. So when you compare the number 125 with a string '125' using the equals (==) operator, the expression evaluates to true.
console.log( 125 == '125' );
Type conversion is not performed when using the identical (===) and not identical (!==) operators.
The second type casting the explicit type casting is done forcefully by the developer for the sake of a good line of code. In JavaScript the type casting can be done only for strings, numbers and Boolean (object) data types.
Examples of the explicit type casting are methods parseInt(), parseFloat() and toString().
let a = 1.015
console.log(a)
console.log(typeof a)
console.log(a.toString())
console.log(typeof a.toString())