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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T15:16:03+00:00 2026-06-14T15:16:03+00:00

After reading about closures in JavaScript, I am still unable to understand where are

  • 0

After reading about closures in JavaScript, I am still unable to understand where are they used? If there were no closures then how would the things be done alternately (if possible) and what does the use of closures simplify. If someone can explain this with some code examples in JavaScript it would be helpful. Any links to articles explaining this are also welcome.
I have read this article mentioned in a similar question. It explains with code like this

    function makeSizer(size) {
      return function() {
        document.body.style.fontSize = size + 'px';
      };
    }

    var size12 = makeSizer(12);
    var size14 = makeSizer(14);
    var size16 = makeSizer(16);

document.getElementById('size-12').onclick = size12;
document.getElementById('size-14').onclick = size14;
document.getElementById('size-16').onclick = size16;

But why would I do like this when instead I can easily create a function like this

function sizer(size) {
            document.body.style.fontSize = size + 'px';
          };

    document.getElementById('size-12').onclick = function(){sizer(12)};
    document.getElementById('size-14').onclick = function(){sizer(14)};
    document.getElementById('size-16').onclick = function(){sizer(16)};
  • 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-06-14T15:16:05+00:00Added an answer on June 14, 2026 at 3:16 pm

    I think this SO answer pretty much explain the concept in detail.
    After reading this my understanding is that closures are there to make functions as first class objects. Functions as first class objects are really helpful as they can be passed like arguments and make certain things quite easy.

    Also one more benefit of using closures is probably they can be used to make members private in JavaScript as explained in this post.

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

Sidebar

Related Questions

I was reading some posts about closures and saw this everywhere, but there is
After reading about Erlang's lighweight processes I was pretty much sure that they were
After reading about the pimpl idiom I was horrified! Isn't there a tool out
After reading about CORS (Cross-Origin Resource Sharing), I don't understand how it improves security.
After reading about the GAE Datastore API, I am still unsure if I need
After reading about using react in actors in Scala, I thought react 's would
After reading about attr_accessible in the Rails 3.1 API , I see that there
After reading about the problem of passing empty std::string objects between DLLs and EXEs,
After reading a description about swapping pointer addresses on Stackoverflow, I have a question
After reading an article about fonts, i tried the code and i am getting

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.