Evaluating "()" in node.js causes wierd behavior, but the browser says a syntax error (error in node.js?)

When I evaluate the expression "()" in node.js (without quotes), it distorts the environment. The global object is broken and nothing works. When I evaluate the same express in the browser console, it reports a syntax error. From my research, it seems that the browser is correct. Is this a bug in the parser of a node.js expression? Can someone explain what is happening under the hood? Here is a screenshot

+4
source share
3 answers

() JavaScript syntax is not valid per se.

Node REPL, . , .

, , :

> () => { // this isn't valid syntax by itself
... }     // but you can complete a valid expression like this

, , ctrl-c.

+3

, JavaScript REPL. JavaScript, ( ). , , , ( , , ).

, , (}, , - , !

, (2, - , ), *, , ..

, (). =>... (-), .

. REPL Node.js, Chrome, Firefox .. , . "", , , .

Node.js " " REPL, , . , -, , , , Ctrl+C.

Chrome . (), :

> ()
Uncaught SyntaxError: Unexpected token )

lambda ()=>, :

> ()=>
2

Node.js REPL, , , :

> eval("()")
SyntaxError: Unexpected token )
+1

, , Node , , . , ((( ) .., . Ctrl-C, .

0

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


All Articles