Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5933311
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T14:57:20+00:00 2026-05-22T14:57:20+00:00

I am totally new to JavaScript and the Facebook SDK. Could someone describe in

  • 0

I am totally new to JavaScript and the Facebook SDK. Could someone describe in English the following feature:

  window.fbAsyncInit = function() {
    FB.init({appId: 'your app id', status: true, cookie: true,
             xfbml: true});
  };
  (function() {
    var e = document.createElement('script'); e.async = true;
    e.src = document.location.protocol +
      '//connect.facebook.net/en_US/all.js';
    document.getElementById('fb-root').appendChild(e);
  }());

i.e. the standard way of “reading” this in English. The “(function (){” bit is where I fall over. I can see what it’s doing: after running this bit async goes on and does the stuff in function(), but what JavaScript feature is this and what are the components?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T14:57:21+00:00Added an answer on May 22, 2026 at 2:57 pm

    The syntax is a little strange. The first bit

    window.fbAsyncInit = function() {
      FB.init({appId: 'your app id', status: true, cookie: true,
               xfbml: true});
    };
    

    Is a function expression. In the context of its use, the developer could also have written:

    function fbAsyncInit() {
      FB.init({appId: 'your app id', status: true, cookie: true,
               xfbml: true});
    };
    

    See this JSFiddle for an equivalent. Either way, calling is identical:

    fbAsyncInit();
    

    the following code:

      FB.init({appId: 'your app id', status: true, cookie: true,
               xfbml: true});
    

    Is calling the Init function on the FB object and passing an object literal as a parameter.

    This bit here takes a little more explanation:

    (function() {
      var e = document.createElement('script'); e.async = true;
      e.src = document.location.protocol +
        '//connect.facebook.net/en_US/all.js';
      document.getElementById('fb-root').appendChild(e);
    }());
    

    This article might help: What does this JavaScript/jQuery syntax mean?

    All variables in JavaScript are ‘hoisted’ to global scope unless they are in a function. The convention you see is an anonymous function that is automatically invoked. We could have written:

    function MyFunc(){
      var e = document.createElement('script'); e.async = true;
      e.src = document.location.protocol +
        '//connect.facebook.net/en_US/all.js';
      document.getElementById('fb-root').appendChild(e);
    };
    MyFunc();
    

    But that would have been extra code and extra variables in memory.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am totally new to javascript and am probably biting of more than I
am totally new to Javascript , but i need it for using googlemaps in
I am totally new to Selenium. I want to execute a javascript snippet in
I am totally new to javascript and I have a very easy to answer
Probably a dead simple and idiotic question (I'm totally new to javascript): I have
I am totally new to SQL . I have a simple select query similar
I am totally new to XSLT and can't work out where I am going
I'm totally new to both java and java Server worlds... But I've a good
I am absolutely and totally new to rails, so the answer is probably very
I am totally new to emacs and is starting to learn how to use

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.