[Javascript] line end character ;

Mark Wonsil wonsil at 4m-ent.com
Wed Jun 23 08:07:26 CDT 2004


Chris Tifer wrote:
> I'm looking at an example of JavaScript 1.5 and here's what is says
> regarding semicolons: 
> 
> =======================
> Multiple statements may occur on a single line if each statement is
> separated by a semicolon. 
> =======================
> Nowhere does it say that it's bad practice to not use it and I've never
> heard that. It's all a matter of preference and consistancy. For example,
> what type of naming conventions you use. It's not neccessary
> to use any one way, but it's just advised that you stick with whichever
> method you do go with.

<kindly_snipped_for_digest_readers />

Language standards rarely enforce "good practices".  Standards are often
compromises between many groups of people with different experiences.  As
far back as Fortran, the compiler implicitly determines the type of the
variable by the starting character.  (icount = Integer, atotal = real, etc.)
In most Fortran compilers, this is still the default.  The best practice is
to turn this feature off and explicitly declare variables.  It is also
considered best practice in (Visual) Basic to declare variables (Option
Explicit).  Many languages don't require the statement separator on the last
line of a block.  Good practice is to include the separator in case another
programmer inserts a line at the end of the block (Pascal, CSS for example).
In web page design, accepting the default background color for the body
element can render your page unreadable because the user changed their
desktop theme to Sandstone Blue or some such.  

For as long as I have been coding, it has been taught to not rely on default
behaviors.  The world changes and your code will break at some point.  Be
explicit as much as you can.

Mark W.





More information about the Javascript mailing list