+ 1

Is it possible to break javascript code into several lines?

5th Sep 2020, 2:43 PM
Akanksha Kumari
Akanksha Kumari - avatar
2 Respuestas
+ 6
There are situations you'll want to avoid line breaks or explicitly use a semicolon where there might be ambiguity for how ASI (Automatic Semicolon Insertion) works. I show a demo of such issues like when using an IIFE (Immediately Invoked Function Expression). https://code.sololearn.com/WzluRho1k50G/?ref=app You'll also want to avoid placing a return value on a separate line from the return statement. Ex: ---- function add(x, y) { return x + y } console.log(add(4, 7)) // returns undefined instead of 11 ---- I highly recommend reading this article to understand the few situations where ASI may cause unintended issues with splitting expressions and statements across several lines. https://medium.com/javascript-in-plain-english/automatic-semicolon-insertion-asi-in-javascript-made-simple-19c48d179494
5th Sep 2020, 8:21 PM
David Carroll
David Carroll - avatar