Skip to content

Instantly share code, notes, and snippets.

@scriptschat
Created September 23, 2020 13:11
Embed
What would you like to do?
type coercion in JavaScript with + operator
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