In chapter 1, Converting Between Strings and Numbers: Are the quotes significant? Why aren't they the same?
const answer = '5' * 1;
const answer = + '5';
In the first one:
const answer = ‘5’ * 1;
In the second one:
const answer = + ‘5’;
The + symbol here is actually the unary plus operator. This explicitly converts the ‘5’ string into a number type.
So in both cases, the end result is that ‘5’ gets converted into the number 5.
But the key difference is that the first example relies on implicit coercion by using * 1. The second uses explicit conversion with the + operator.
So while the end result is the same (a number 5), the * 1 and + operators work differently under the hood to convert between the string and number types.
The quotes indicate it starts as a string, while leaving them off would indicate a number to begin with. The quotes are significant in signaling the starting data type before the conversion.
Hope this helps explain why those two approaches are not exactly the same even though the end result is! Let me know if any other questions come up.
Some people consider implicit conversions such as that to be a nice convenience. When implicit conversions cause confusion it might be considered a disadvantage of the language.
Hah, I’d say it’s a typo. I’ll mention it on GitHub.