+ 1
Is it possible to break javascript code into several lines?
1 ответ
+ 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