Line break within arrow function throws “Uncaught SyntaxError: Unexpected token `=>`”

后端 未结 2 1611
天涯浪人
天涯浪人 2021-01-25 22:22

I’m getting the error “Uncaught SyntaxError: Unexpected token => on my console when I put the e parameter in parentheses and then use an E

2条回答
  •  庸人自扰
    2021-01-25 23:05

    Arrow functions cannot have a newline between the parameters and the =>:

    14.2 Arrow Function Definitions

    ArrowFunction[In, Yield, Await]:

    • ArrowParameters [?Yield, ?Await] [no LineTerminator here] => ConciseBody

    Either remove the newline, or put it somewhere else. You could also use a named function instead, eg:

    const submitHandler = (e) => {
      // ...
    };
    document.querySelector("#book-form").addEventListener("submit", submitHandler);
    

提交回复
热议问题