+ 6
JavaScript code running perfectly without using semicolon.why?
This JavaScript code run without any error without using semicolon.does semicolon is not a mandatory in JavaScript. https://code.sololearn.com/Wk4uhK3w5IBG/?ref=app
7 ответов
+ 8
Morpheus's links:
quick: https://news.codecademy.com/your-guide-to-semicolons-in-javascript/
in depth : http://www.bradoncode.com/blog/2015/08/26/javascript-semi-colon-insertion /
official: http://www.ecma-international.org/ecma-262/6.0/index.html#sec-automatic-semicolon-insertion (see chapter 11.9)
+ 10
These previously asked threads maybe helpful :
https://www.sololearn.com/Discuss/1742884/?ref=app
https://www.sololearn.com/Discuss/1671031/?ref=app
https://www.sololearn.com/post/36048/?ref=app
+ 3
Semicolons are a big debate in the js community.
It doesn't need semicolons, it places them on its own automatically.
People claim using the semicolons makes the code easer to read, less chance of unexpected behaviour and it doesn't make you forget semicolons in other languages
People who claim NOT using semicolon makes (ironically) the code cleaner and easier to read,less chance of unexpected behaviour and dev can focus on logic instead of syntax.
Online tutorials are very insistent on semicolon - once you check codes from talented js devs you will see that the majority doesn't use them.
What I think is a great way of approaching this issue:
Just stick to one style through the document or do whatever your team is doing.
Neither will break your code, just keep it consistent and do what feels easier to read
+ 3
I am wondering, what would be specific cases where omitting a semicolon will lead to unexpected behaviour?
0
Wait 😦 What 😦
Check your code or may be your compiler is auto
0
I’ve been using Javascript for about three years, and through my experience I think that you don’t need to use semicolins after every statment. But some statements require you to use a semicolon like: break(); and return(); But generally you should just get into the habbit of using one after ever statement.
- O White