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

后端 未结 2 1578
天涯浪人
天涯浪人 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:01

    First of all, your function call and function declarations are not closed. Secondly, the arrow cannot be on its line alone.

    //Event: add book
    document.querySelector("#book-form").addEventListener("submit", (e) => {
      //prevent default
      e.preventDefault();
      // get form value
      const title = document.querySelector("#title").value;
      const author = document.querySelector("#author").value;
      const isbn = document.querySelector("#isbn").value;
    //Close function body, then function call.
    });
    

提交回复
热议问题