Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does "true && () => {}" produce "Uncaught SyntaxError: Malformed arrow function parameter list"? [duplicate]

The following code, when executed,

true && () => {}

yields

Uncaught SyntaxError: Malformed arrow function parameter list

Why ?

Edit: I know wrapping the function in parenthesis works, thanks everyone, but I'd like to understand why can't the parser figure out it's a function in the first place.

like image 265
João Pinto Jerónimo Avatar asked Apr 01 '19 13:04

João Pinto Jerónimo


1 Answers

The reason is due the first part true || (a) being parsed by itself and THEN the parser is trying to parse the rest => {}, which causes the error.

like image 200
Ivan Castellanos Avatar answered Oct 07 '22 02:10

Ivan Castellanos