0

I have seen some functions inside ( ), and then I did a little research and found it was called closures. But I'm not really sure if that's what it is or closures are Classes.

What I mean is the following:

<script>(function e() { console.log("hello world"); })</script>

Why is the function e() inside(), what does that means?

Is it anyhow related to the following code?

function() C {
    e = function() { console.log("hello world"); };
}
TheCodeArtist
  • 21,479
  • 4
  • 69
  • 130
Christopher Francisco
  • 15,672
  • 28
  • 94
  • 206
  • I'm not sure what you're asking. You're asking why the inner function has parentheses after it? – Robert Harvey Jul 25 '13 at 18:18
  • FYI, every function in JS is a closure, the `(...)` around them have nothing to do with that. They are used to force the JavaScript engine to interpret the function definition in a certain way (as a *function expression*). – Felix Kling Jul 25 '13 at 18:18
  • Parentheses are just a way to encapsulate an expression, which is not a closure. A closure (really, just a function) is used to define variable scope (which, in JS, is basically function-scope). – Matthew Blancarte Jul 25 '13 at 18:19

0 Answers0