Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions explicit-and-implicit-conversion-in-javascript.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,19 @@ Use console.log() to clearly show the before-and-after type conversions.
*/


let result = "5" - 2;
console.log("The result is: " + result);
let result = "5" - 2;//converts "5" into number automatically
console.log("The result is: " + result);// 3

let isValid = Boolean("false");
let isValid = Boolean("false");//false is truthy
if (isValid) {
console.log("This is valid!");
console.log("This is valid!");// true
}

let age = "25";
let totalAge = age + 5;
console.log("Total Age: " + totalAge);
let totalAge = Number(age) + 5;//Number() function is used to convert string into number
console.log("Total Age: " + totalAge);// 30

console.log("5" * "2");// 10 - Example for Implicit type conversion

let num = null;
console.log(Boolean(num));// false - Example for Explicit type conversion