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

  • SEARCH
  • Home
  • 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 6706443
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:31:16+00:00 2026-05-26T07:31:16+00:00

in the last few days i’m interesting in anonymous function in javascript , so

  • 0

in the last few days i’m interesting in anonymous function in javascript , so i started to “explore” frameworks such as jquery , in the very first line i saw this piece of code :

var jQuery = (function() { .. functions .. }();

and a question came in mind – what is the purpose of that code?
why a variable contain anonymous function? what is the uses with that var? is it kind of function container or something? if it is how to access the functions?

  • 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-26T07:31:17+00:00Added an answer on May 26, 2026 at 7:31 am

    what is the purpose of that code?

    You are actually missing a closing parenthesis for this code to be valid javascript:

    var jQuery = (function() { ... })();
    

    It defines an anonymous function and executes it immediately storing the result of it in the variable.

    You can think of it like this:

    var jQuery = foo();
    

    It’s just that they didn’t bother to define foo as an external function as they didn’t need to call it elsewhere in the code. So they defined it as an anonymous function.

    By doing this everything that is declared inside this anonymous function is scoped and accessible only to the containing anonymous function. It is not accessible to the outside.

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

Sidebar

Related Questions

I searched for Java based web application frameworks the last few days. I have
I have spent the last few days playing around with Drupal for the first
i was exploring in the last few days how big frameworks works , how
Over the last few days I have noted a few web sites that demonstrated
For the last few days I have been attempting to find a method to
thanks for all the help the last few days. I'm hoping someone knows this
I'm playing with ASP.NET MVC for the last few days and was able to
This is a shoutout as I've been spending the last few days learning about
I've been teaching myself Dojo over the last few days. However, if you look
I have spent the last few days attempting to integrate a Grails (version 1.3.2)

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.