What does the first semicolon imply? " ;( function( ) { } ) ( ); " [duplicate]

StackOverflow https://stackoverflow.com/questions/17678557

  •  03-06-2022
  •  | 
  •  

質問

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?

役に立ちましたか?

解決

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.

他のヒント

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

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top