"not required" vs "incorrect"

This commit is contained in:
joaquinelio 2021-05-29 18:40:18 -03:00 committed by GitHub
parent cf33b67042
commit 4c35f5998a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -46,7 +46,7 @@ alert(3 +
+ 2); + 2);
``` ```
The code outputs `6` because JavaScript does not insert semicolons here. It is intuitively obvious that if the line ends with a plus `"+"`, then it is an "incomplete expression", so the semicolon is not required. And in this case that works as intended. The code outputs `6` because JavaScript does not insert semicolons here. It is intuitively obvious that if the line ends with a plus `"+"`, then it is an "incomplete expression", so a semicolon there would be incorrect. And in this case, that works as intended.
**But there are situations where JavaScript "fails" to assume a semicolon where it is really needed.** **But there are situations where JavaScript "fails" to assume a semicolon where it is really needed.**