Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parenthesis for anonymous JavaScript functions

Are they the same?

var multiply = function () {
      //..
      }();

var multiply1 = (function () {
      //..
      }());
like image 493
johnny Avatar asked Jul 09 '11 16:07

johnny


People also ask

What goes in the parentheses of a function JavaScript?

In JavaScript, the functions wrapped with parenthesis are called “Immediately Invoked Function Expressions" or "Self Executing Functions. The purpose of wrapping is to namespace and control the visibility of member functions. It wraps code inside a function scope and decrease clashing with other libraries.

What does () => mean in JavaScript?

It's a new feature that introduced in ES6 and is called arrow function. The left part denotes the input of a function and the right part the output of that function.

Can functions be anonymous in JavaScript?

Anonymous Function is a function that does not have any name associated with it. Normally we use the function keyword before the function name to define a function in JavaScript, however, in anonymous functions in JavaScript, we use only the function keyword without the function name.

How do you use parentheses in JavaScript?

Parenthesis are used in an arrow function to return an object. Parenthesis are used to group multiline of codes on JavaScript return statement so to prevent semicolon inserted automatically in the wrong place.


1 Answers

As mquander said in that case they are the same, but if you want to read a little more about it you can go to: An Important Pair of Parens.

like image 63
nicosantangelo Avatar answered Nov 09 '22 04:11

nicosantangelo