Why does the JavaScript need to start with “;”?

I have recently noticed that a lot of JavaScript files on the Web start with a ; immediately following the comment section.

For example, this jQuery plugin’s code starts with:

/**
 * jQuery.ScrollTo
 * Copyright (c) 2007-2008 Ariel Flesler - aflesler(at)gmail(dot)com | http://flesler.blogspot.com
 * Dual licensed under MIT and GPL.
 * Date: 9/11/2008                                      
 .... skipping several lines for brevity...
 *
 * @desc Scroll on both axes, to different values
 * @example $('div').scrollTo( { top: 300, left:'+=200' }, { axis:'xy', offset:-20 } );
 */
;(function( $ ){

Why does the file need to start with a ;? I see this convention in server-side JavaScript files as well.

What are the advantages and disadvantages of doing this?

3 Answers
3

Leave a Comment