Closing each code line


#1

Is it absolutely necessary for me to put a ";" at the end of each code line in order for the code to work?


#2

Read Automatic semicolon insertion in
the =Book=
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Lexical_grammar

=discussions / opinions=
http://stackoverflow.com/questions/17036135/why-is-it-that-semicolons-are-not-used-after-if-else-statements
http://stackoverflow.com/questions/25101936/why-does-adding-a-semicolon-sometimes-break-an-if-statement
google search
javascript semicolon necessary site:stackoverflow.com


#3

If you don't put it in it will be automatically inserted for you where the interpreter "thinks" you'd like it to have been. This can sometimes produce unintended results especially for beginners.

When you get very comfortable with the language and are familiar enough with the interpreter to let it take care of your semi's then go for it. Until then it's probably a good idea to use semi-colons since they'll have to be in your code one way or another.

As with most things there are strong feelings out there regarding semi colons in JS. Some of the more prominent speakers on the subject have differing views so you're validated no matter what you do so long as you do it deliberately, consistently, and with understanding.


#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.