1

I'm really sorry with the title, and im sorry if im asking this noob questions here, because i don't know what the keyword for this in google.

Ok, first i'm new to javascript and still learning this programming language. so i've seen this alot, but i don't know what it's mean

var myapp = function(){

  var a = 'a';
  var b = function(){
    //some code goes here
  }

  return {

    init: function(){
    b();
    //some code goes here

    }

  }

}() <-- what is it?;

So i've been wondering what this symbol '()' do at the end. and why many people writing a function inside a variable?

Ahmad Milzam
  • 129
  • 3
  • 8

1 Answers1

3

That means that the function is being exectued right after its declaration

On the other hand, declaring the function this way:

var myapp = function(){

lets you use it as an object..

Then you can use myapp.init() for example

Pablo Matias Gomez
  • 6,614
  • 7
  • 38
  • 72