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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:17:35+00:00 2026-05-31T13:17:35+00:00

In this article http://howtonode.org/why-use-closure an example is given : function greeter(name, age) { var

  • 0

In this article http://howtonode.org/why-use-closure an example is given :

function greeter(name, age) {
  var message = name + ", who is " + age + " years old, says hi!";

  return function greet() {
    console.log(message);
  };
}

// Generate the closure
var bobGreeter = greeter("Bob", 47);

// Use the closure
bobGreeter();

Why would it be more worth than

function greeter(name, age) {
  var message = name + ", who is " + age + " years old, says hi!";
    console.log(message);
}

greeter("Bob", 47);

which is much shorter and does apparently the same thing ? Or it doesn’t ?

Update 2: could it be usefull somehow for this case Solving ugly syntax for getter in js

  • 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-31T13:17:36+00:00Added an answer on May 31, 2026 at 1:17 pm

    It does not do the same thing. The second example forces you to print the output right on the spot, while the first one allows you to delay it.

    To put it another way: in the first case, you do not need to print the output right at the point where you have age and name in scope; in the second example, you do.

    Of course it’s true that you need to somehow “transport” bobGreeter to the scope where you will actually call greet on it, and needing to transport 1 value instead of 2 is not the most compelling argument. But remember that in the general case it’s 1 against N.

    There there are also many other reasons that make closures compelling that cannot be illustrated with this particular example.

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

Sidebar

Related Questions

According to this article http://wiki.eclipse.org/FAQ_How_do_I_load_and_save_plug-in_preferences%3F we're supposed to use preferences as shown below. Preferences
After reading this article http://lukast.mediablog.sk/log/?p=155 I decided to use mingw on linux to compile
Taking this article on classes and structs as an example: http://msdn.microsoft.com/en-us/library/ms173109.aspx namespace ProgrammingGuide {
In this article http://www.jroller.com/eyallupu/entry/hibernate_the_any_annotation and also in this question How to use Hibernate @Any-related
In this article http://nagios.sourceforge.net/docs/3_0/eventhandlers.html#example they show how to get arguments from nagios to shell
As guide I use this article http://msdn.microsoft.com/en-us/library/bb668969.aspx After step 3 (Analyzing sourcesafe folder) I
according to this article http://electricbeach.org/?p=653 and many others it's trivial to make a layout
I stumbled upon this article http://www.thefloatingfrog.co.uk/css/my-hatred-of-br-clearall/ When would one need to use that ?
I customize a collapsible sidebar from this article (http://devheart.org/articles/jquery-collapsible-sidebar-layout/) for my own project But
I configured an instance of Tomcat following this article: http://tomcat.apache.org/tomcat-6.0-doc/ssl-howto.html . I commented out

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.