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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T23:07:00+00:00 2026-06-18T23:07:00+00:00

This seems like such a dumb question but… If we have a constructor: function

  • 0

This seems like such a dumb question but…
If we have a constructor:

function Candy(name) {
    this.name = name;
}

and we extend the prototype of this object Candy:

Candy.prototype.printName = function(name) {
    console.log(this.name);
};

then we create a new object from the Candy constructor and run the inherited method for this new object:

var chocolate = new Candy("chocolate");
chocolate.printName();

It’s not clicking with me as to why we get chocolate as an output.
When we create the chocolate object from the constructor have we in essence done this:

var chocolate = new Candy();
chocolate.name = name;  

and if so, why is it that when we run:

chocolate.printName();  

with a blank argument, it spits out: “chocolate”?
Isn’t chocolate simply the name of the object that we built out of the Candy construcor?
As in, chocolate is not what we have assigned the chocolate.name parameter to be, but name is. Since we passed an empty argument field, why are we getting “chocolate” and not name back?

  • 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-18T23:07:01+00:00Added an answer on June 18, 2026 at 11:07 pm

    The parameter name in the printName method is never used. To call the method with the signature that you specified, you would do like this:

    chocolate.printName("Fudge");
    

    That would send the string "Fudge" into the method as the parameter name, but the parameter is ignored, and it still prints out the name that you specified for the object instead.

    Javascript allows you to call any function with any number of parameters. If you use too few parameters, the rest of the parameters will just have the value undefined, and if you use too many parameters, they will be in the arguments collection, but they will not be put in a parameter variable.

    So, if you call chocolate.printName();, the parameter name will have the value undefined. If you call chocolate.printName(1,2,3), parameter name will have the value 1, and the other values would be available inside the function as arguments[1] and arguments[2].

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

Sidebar

Related Questions

This seems like such a simple question, but I have been trying for an
This seems like such a simple question. I have several Edit boxes on my
this seems like such a simple problem but I have been unable to find
This seems like such a trivial question to ask, but it's been vexing me
This seems like such a rookie question but I'm just banging my head against
This seems like it should have such a simple solution, but apparently it doesn't.
This seems like such a simple question, but I've given it the obligatory 30
This seems like such an obscure question, but here it goes: Is there a
This seems like such a ridiculous question, but our intranet portal which hosts hundreds
Sorry, this seems like such an obvious question, but I just can't find an

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.