I
I
Itvanya2015-03-10 18:14:22
JavaScript
Itvanya, 2015-03-10 18:14:22

Anonymous JavaScript functions or what do parentheses do?

Guys, hello. In general, I have no problems as such with js. At this stage, I just try to understand all the features of the language well.
We all know the standard anonymous function:

(function(a, b) {
  return a + b;
})(2, 4)

Above is a completely simple anonymous self-calling function. Everything is very clear here. I'm interested in this part:
(function(a, b) {
  return a + b;
})

If we do not return anything from an anonymous function, but simply frame it with brackets (this process is called parsing the function inside the brackets and returning the function object), then the function body is returned from these brackets.
function (a, b) {
  return a + b;
}

My question is: what exactly is the role of parentheses when calling (or +/! symbols, which can also be put in the very first parenthesis) an anonymous self-invoking function? Can this effect be considered similar to what we get when assigning an anonymous function to a variable?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
S
Sergey, 2015-03-10
@Itvanya

Immediately-invoked_function_expression

L
Lynn "Coffee Man", 2015-03-10
@Lynn

learn.javascript.ru/function-declaration-expression

I
ialse, 2021-04-02
@ialse

Keywords iife
https://learn.javascript.ru/closure#iife
This is an obsolete technique, today it is usually not used

A
Andrey Sanych, 2017-12-27
@lemonlimelike

at you in the circuit the match table is created, and at selection - matches. Probably the name of the table is incorrectly spelled in the model

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question