JavaScript code running perfectly without using semicolon.why? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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

2nd Jan 2020, 12:10 PM
Maninder $ingh
Maninder $ingh - avatar
7 Answers
+ 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
2nd Jan 2020, 12:20 PM
HNNX 🐿
HNNX 🐿 - avatar
+ 3
I am wondering, what would be specific cases where omitting a semicolon will lead to unexpected behaviour?
2nd Jan 2020, 12:25 PM
HonFu
HonFu - avatar
0
Wait 😦 What 😦 Check your code or may be your compiler is auto
3rd Jan 2020, 6:39 PM
Cyber Ninja
Cyber Ninja - avatar
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
4th Jan 2020, 3:18 AM
O. White
O. White - avatar