Why: 3.toString () calls Node.JS REPL to enter a new scope?

When I enter a literal integer and then .toString()in Node, it enters a new area by answering ....

Examples

> 3.toString()
...

> 'foo:' + 3.toString()
...

> 'foo:' + 3.toString() + ':bar'
...

Other types work fine

> true.toString()
'true'

Even that works!

> 10.50.toString()
'10.5'

Bypass

Wrap around the letter integer in brackets:

> (3).toString()
'3'

Is there a reason for this, or do you think this is a mistake?

+4
source share
1 answer

, , JavaScript , , . - 5.toString() JavaScript toString, . , . , ( ) :

5..toString()

JavaScript 5 float 5, , . JavaScript .

, , , JavaScript , . , :

5+''

:

console.log('We will need '+ 5+5 + 'pizzas.');
//"We will need 55 pizzas."
console.log('We will need '+ (5+5) +' pizzas.');
//"We will need 10 pizzas."
+7

Source: https://habr.com/ru/post/1539359/


All Articles