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 3454098
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T09:27:09+00:00 2026-05-18T09:27:09+00:00

I saw this syntax many times but I couldn’t find a way to google

  • 0

I saw this syntax many times but I couldn’t find a way to google it properly, I hope I can get some help here:

  <script>
    (function(){
      //code goes here
    })();
  </script>

Why is the function keyword wrapped in the parenthesis? What does it do and what is this called?

  • 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-18T09:27:09+00:00Added an answer on May 18, 2026 at 9:27 am

    In js, the syntax:

    function() { //code }
    

    defines an anonymous function. You can store this into a variable and call it:

    var a = function() { //code };
    a();
    

    or if you don’t want to bother assigning it you can do it in one step.

    (function() { //code })();
    

    the parenthesis are necessary because:

    function() { //code }();
    

    is not proper syntax.

    This syntax is useful in certain situations to help memory management as well as change variable names. For example in javascript you have a jQuery object, but most people refer to it as $. But sometimes $ is used as some other variable instead of the jQuery object. To fix this, you can wrap your code in:

    (function($) { // code that uses $ })(jQuery);
    

    That way you can use the dollar sign and not have to worry whether or not it actually points to the jQuery object or not.

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

Sidebar

Related Questions

Possible Duplicate: What does this CSS shorthand font syntax mean? I saw many people
I saw this posting which explained how to get BC3 working as the diff
I saw this topic and implement IntentService as describes, but what if I want
I can't understand what causes a syntax error in a user defined function. This
This seems like a really simple question but somehow my Google-Fu failed me. What's
I've read a post here about password encoder, and saw this syntax: passwordEncoder.isPasswordValid(user.password, params.password,
I saw this syntax: @helper IncludeJS(string url) { <script src=@url type=text/javascript></script> } Placed on
I saw this syntax on another StackOverflow post and was curious as to what
Ok, I spend many time on this, I don't get what I'm doing wrong.
I saw this question and it really shedded some light. Despite this, I can't

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.