// No effect on numbers
let x = 1;
alert( +x ); // 1
let y = -2;
alert( +y ); // -2
// Converts non-numbers
alert( +true ); // 1
alert( +"" ); // 0
+ isn't convert anything to a number at all.
Code:var a = "1"; var b=2; var c= a + b; alert(c); //WILL ALERT 12 (1+2) //BUT var c=parseFloat(a)+b; alert(c); //WILL ALERT 3;
const a = "1";
const b = 2;
const c = + a + b;
alert(c);
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.