+ 10
JavaScript
Semicolon it is optional in JavaScript and why?
17 Answers
+ 13
Semi colon is optional in js. I also prefer not to use it because that's what I used to hate most about java.
But there are some places where it is necessary to use semi colon is js.
Btw a article u should must read about it :
https://zellwk.com/blog/semicolons/
+ 11
Oh you are not using the app on mobile.
Below quotes Morpheus's original wordings in his JS Fact Series #013:
Maz I m glad you asked, I was waiting for this question :-)
Actually if we write codes correctly then we dont need to use semicolons, but mistakes happen and the problem is ASI will cover your mistake without even throwing an error,
thats y linters like JShint, JSlint throw warning on missing semicolons on those bad scenarios. and in general its a good habit to include them,
regarding those statements here are the 3 articles
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
For those of us who have got used to using semicolons at the end of statements, seeing code without semicolons is a bit like seeing sentences without full stops (periods). But that's just opinion and we just have to think outside our universe. When semicolons are optional, meaning sometimes present, sometimes absent, that adds even more confusion. But hey, that's just how JS is.
+ 6
thank Mamoudou for answer
but i am writing js code and did not use semicolon and the code work well , try write code in your pc without semicolon and tell me the result
+ 6
You are welcome.
If you have installed the Sololearn mobile app, feel free to read Morpheus JS Fact Series from start to finish, they are treasures of Sololearn.
+ 4
no semicolon are not optional in JS, because its mean the end of an expression.
+ 4
Yes for JS semicolon is optional in most situation. But using it is good practice.
https://www.sololearn.com/post/36048/?ref=app
P.s. As the links to the readings are hidden in some replies, it is easier to access the reading via the index :
https://code.sololearn.com/Wyr76080kKxS/?ref=app
+ 4
You are welcome, have you read the three readings?
+ 4
thanks Gordon it so helpful
+ 3
no semicolon are not optional in JS, because its mean the end of an expression.
+ 3
thank you Gordon
+ 3
page not found
+ 3
In some environments it mandatory AFAIK 🙄
I prefer to use it....☕
+ 1
Mostly semi colon indicates the end of code
+ 1
The semicolon is not really optional. Javascript automatically inserts the semicolon if you forget to add one without throwing an error. But sometimes it can insert a semicolon at the wrong place or not add one when one is needed. So best practice is to use semicolons.
0
java andraed
0
اختراع جافا اندرايد