Semicolon after statement | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Semicolon after statement

Shouldn't the semicolon be obligatory also after the whole "if" statement, not only inside it? (after curly braces)

7th Jan 2017, 11:02 AM
IgiPap
3 Answers
+ 8
You put it only where code is executable. example: alert("hi"); //action if (a == 1){} //the action isn't performed by the "if", it's performed by the code inside it...
7th Jan 2017, 11:20 AM
Valen.H. ~
Valen.H. ~ - avatar
+ 6
Well... you can do this : alert(prompt("text")); (no need for semicolon after prompt because it returns value to alert thus isn't considered as action) i don't think there are any exceptions, and if you remove it there are 50% chances that the code will malfunction (because some functions are actions only and don't return value)...
7th Jan 2017, 2:59 PM
Valen.H. ~
Valen.H. ~ - avatar
+ 3
Thanks a million! One, ok two more questions: are there any exceptions? Will it change anything if I'd add semicolon after i.e. the statement you mentioned?
7th Jan 2017, 2:46 PM
IgiPap