1

I was just going through the source code of cordova.js, its structure is like

;(function() { cordova code I have yet to understand })();

Just curious what does the first semi-colon imply?

Is it just to make sure that there is a semicolon preceding the anonymous function or does it mean something else?

Felix Kling
  • 795,719
  • 175
  • 1,089
  • 1,143
ankyskywalker
  • 1,462
  • 2
  • 9
  • 20
  • 1
    Implies that the author wants to make sure any previous statement is successfully terminated. Especially useful when combining several JS files into one. The `()` in JavaScript can be interpreted as the postfix "call" operator, which most likely yield an undesired behavior on the result of a previous expression. –  Jul 16 '13 at 14:01

2 Answers2

2

It is a defensive semicolon, this is in case someone concatenates some JavaScript before your code, and this concatenated code forgot to put a terminating semicolon.

employee-0
  • 1,023
  • 1
  • 9
  • 19
0

It's just to prevent an error if you combine multiple js files. So you can remove it if you want.

Laszlo
  • 2,225
  • 19
  • 22