I started JavaScript programming last month, i know basic syntax like objects, functions, class, string, array, property. Now i was puzzled on given syntax.
Syntax:
(function(){
"use strict";
})();
My question is, why two parenthesis( one contains ‘function’ and another “empty” ) are included in the definition? can some one help me why we use this?.
What you have there is a self-invoking function.
It pretty much is exactly that, a function which immediately gets called. To accomplish that, we need a function expression, not a function declaration. To achieve that, we can do certain things, one of those is, to put the whole expression in parenthesis
this statement creates a function expression. Now all we have left to do is, to invoke that function by appending additional function parenthesis, like we would do with any function
You can also put the function parenthesis into the whole statement, it makes no difference
Another option to bring a function into an expression form is by using
!or+signs infront of itAnything goes, as long we create an expression, we can’t invoke a function declaration like that