1.

How ECMAScript is related to JavaScript?

Answer»

Library in JavaScript has a FUNCTION with a leading semicolon:

;(function ) { }

Let us see the different uses of including a leading semicolon:

  • Concatenate

The purpose to include semicolon is to safely concatenate several JS files into one.

  • Preceding Code

A leading semicolon protects from preceding code, which may have been improperly closed. A semicolon prevents this from occurring. If this is the case, then adding a semicolon will fix it.

  • Appending

The leading semicolon in immediately-invoked function expressions PREVENT errors when appending the file during CONCATENATION. This concat is to a file containing an expression improperly concluded with a semicolon

Let’s see an example. Let’s SAY we are concatenating two files with self-invoking functions:

  • Function ONE
(function(){...ONE...})()
  • Function TWO
(function(){...TWO...})()
  • Now concatenating it will give the following result:
(function(){...ONE...})() (function(){...TWO...})()
  • Function TWO can have a leading semicolon:
!(function(){...TWO...})()
  • Now after concatenation, you can see the semi-colon is VISIBLE:
(function(){...ONE...})();(function(){...TWO...})()

This helps in preventing any kind of errors when appending the file during concatenation.



Discussion

No Comment Found