Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Implicit conversion in Javascript

Tags:

javascript

Why are the following results different using JavaScript?

console.log(1 + + "2"); // => 3
console.log(1 + "2"); // => 12

Is there an implicit conversion in JavaScript?

like image 744
Ala Avatar asked May 22 '26 22:05

Ala


1 Answers

No, the unary plus operator (the second +) explicitely converts a string to a number.

like image 165
Jonas Wilms Avatar answered May 25 '26 10:05

Jonas Wilms



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!