type coercion in JavaScript with + operator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function sum() { | |
var a = new Number('3'); | |
//Converts String value '3' to numeric value 3 | |
var b = +'4'; | |
//Converts String value '4' to numeric value 4 | |
var c = a + b; | |
//If there is any issue in conversion it must return NaN as output | |
console.log(c); | |
// Output is numeric value 7 | |
} | |
sum(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment