1

I guess that javascript will parse (2).valueOf() to new Number(2).valueOf() but why it doesn't for the first one ?

According to the operator precedence, the grouping operator shall have a higher priority than the member access https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Operator_Precedence

So why (2) is not be evaluated first and yield 2 instead of be parsed to new Number(2) ?

user3003238
  • 1,517
  • 10
  • 17

1 Answers1

5

Because in 2.valueOf the . is considered to be as a part of 2 instead of being understood as method accessing.

That is why 2..valueOf() works.

console.log(2..valueOf());
void
  • 36,090
  • 8
  • 62
  • 107