en.javascript.info icon indicating copy to clipboard operation
en.javascript.info copied to clipboard

Add explanation of Unary plus (+) operator to Extract for money strings exercise

Open martinDolan opened this issue 1 year ago • 3 comments

The solution to Extract the money problem, uses the unary + operator, however, I don't see that explained anywhere in the Strings section. Adding an explanation of that would be helpful.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Unary_plus

function extractCurrencyValue(str) {
  return +str.slice(1);
}

martinDolan avatar Apr 23 '24 14:04 martinDolan

I don't see that explained anywhere in the Strings section. Adding an explanation of that would be helpful.

This has already been mentioned in the article "Basic operators, maths", there is even a task on this topic. If a potential reader hasn't internalized the information in this chapter, and in the "JavaScript Fundamentals" section in general, I don't think reading the "Strings" article in the "Data Types" section will do him any good.

Alexandre887 avatar Apr 24 '24 17:04 Alexandre887

Understandable assuming everyone reads from beginning to end. I didn't read the Basic operators, maths section, but maybe a link to that would be useful to some.

martinDolan avatar Apr 24 '24 17:04 martinDolan

Don't see much point to it. I don't think anyone resorts to solving such problems and using string methods without knowing such elementary things as unary plus. It is equivalent to explaining what an object is in the Classes chapter.

But, for that matter, then it would be more logical to replace +prompt(...) with Number(prompt(...)) instead of explaining the purpose of the $+$ in the notation. But even this is, in my opinion, an unnecessary measure.

Alexandre887 avatar Apr 24 '24 17:04 Alexandre887