Double or single quotes make the expression between them a string, Number() turns /* in case it consists of digits, but is a string */ the expression between it's braces into a number. Nothing but a simple magic <wink>
The unary plus or, in other words, the plus operator + applied to a single value, doesn’t do anything to numbers. But if the operand is not a number, the unary plus converts it into a number.
For example:
Code:
// No effect on numbers
let x = 1;
alert( +x ); // 1
let y = -2;
alert( +y ); // -2
// Converts non-numbers
alert( +true ); // 1
alert( +"" ); // 0
Yes my bad. I've tried it by myself. Anyway. That's a really bad habit of coding which nobody should ever get used to. NEVER MIX TYPES.
But my claim is still right. An Math operator isn't convert any type to another type. In that particular example it worked.
Ask a Question
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.