Skip to content

Instantly share code, notes, and snippets.

@scriptschat
Created September 23, 2020 13:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scriptschat/98fc6c3917a35c05f3040982094786b3 to your computer and use it in GitHub Desktop.
Save scriptschat/98fc6c3917a35c05f3040982094786b3 to your computer and use it in GitHub Desktop.
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