+ 10

JavaScript

Semicolon it is optional in JavaScript and why?

31st Mar 2019, 10:55 AM
Khalid Issa Talaf Ibrahim
Khalid Issa Talaf Ibrahim - avatar
17 ответов
+ 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/
31st Mar 2019, 2:50 PM
Arushi Singhania
Arushi Singhania - avatar
+ 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)
31st Mar 2019, 1:41 PM
Gordon
Gordon - avatar
+ 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.
1st Apr 2019, 3:07 AM
Sonic
Sonic - avatar
+ 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
31st Mar 2019, 11:59 AM
Khalid Issa Talaf Ibrahim
Khalid Issa Talaf Ibrahim - avatar
+ 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.
31st Mar 2019, 3:27 PM
Gordon
Gordon - avatar
+ 4
no semicolon are not optional in JS, because its mean the end of an expression.
31st Mar 2019, 11:04 AM
Mamoudou Sylla
Mamoudou Sylla - avatar
+ 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
31st Mar 2019, 1:06 PM
Gordon
Gordon - avatar
+ 4
You are welcome, have you read the three readings?
31st Mar 2019, 1:27 PM
Gordon
Gordon - avatar
+ 4
thanks Gordon it so helpful
31st Mar 2019, 3:21 PM
Khalid Issa Talaf Ibrahim
Khalid Issa Talaf Ibrahim - avatar
+ 3
no semicolon are not optional in JS, because its mean the end of an expression.
31st Mar 2019, 11:05 AM
Mamoudou Sylla
Mamoudou Sylla - avatar
+ 3
thank you Gordon
31st Mar 2019, 1:22 PM
Khalid Issa Talaf Ibrahim
Khalid Issa Talaf Ibrahim - avatar
+ 3
page not found
31st Mar 2019, 1:33 PM
Khalid Issa Talaf Ibrahim
Khalid Issa Talaf Ibrahim - avatar
+ 3
In some environments it mandatory AFAIK 🙄 I prefer to use it....☕
7th Sep 2020, 8:08 AM
Sanjay Kamath
Sanjay Kamath - avatar
+ 1
Mostly semi colon indicates the end of code
30th Jul 2020, 11:23 PM
Silas Silikhe
+ 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.
9th Mar 2021, 6:17 AM
Ryan Els
Ryan Els - avatar
0
java andraed
17th Feb 2020, 8:26 PM
Cut cut pro Cut cut pro
Cut cut pro Cut cut pro - avatar
0
اختراع جافا اندرايد
17th Feb 2020, 8:27 PM
Cut cut pro Cut cut pro
Cut cut pro Cut cut pro - avatar