What does the leading semicolon in JavaScript libraries do?

JavascriptWeb DevelopmentFront End Technology

A function in JavaScript looks like the following:


A library in JavaScript shows a function, which begins with a semicolon, for example:

;(function ) {

The semicolon allows to safely concatenate several JS files into one. This is to serve it faster as one HTTP request.

A leading semicolon can also be to protect from preceding code, which may have been improperly closed. A semicolon will definitely prevent this from happening.

Published on 09-Jan-2018 13:54:39