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

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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:29:05+00:00 2026-05-25T20:29:05+00:00

I wasn’t sure how to ask this, and I apologize if it’s been asked

  • 0

I wasn’t sure how to ask this, and I apologize if it’s been asked already, but I could not find it or an answer.

What is returned when you assign a function to a var.

    var obj = function(){
        this.name = 'Steve';
    }
    alert( obj.name === '');//true
    obj.name = 'Mike';
    alert( obj.name === '');//true
    obj.foo = 'fall';
    alert( obj.foo );//fall

I know obj is now a function/object and I can call obj(). I also know that the function attached to obj is a constructor for new objects of type obj. If I do

var newObj = new obj();
alert( newObj.name );//Steve

“Steve” is printed. etc. etc.

Why does obj seem to have a property called “name” attached to it? And why when I try to assign a value to that property does it not get assigned?

  • 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-25T20:29:06+00:00Added an answer on May 25, 2026 at 8:29 pm

    Because function objects have aname property (which is non-standard by the way) that represents the “name” of the function, your function shows an empty string ("") as the value of this property because it’s anonymous.

    For example, if you declare a function with the name foo:

    function foo() {}
    foo.name; // "foo"
    
    
    var anon = function () {};
    anon.name; // "", an anonymous function
    
    var namedFunctionExpr = function bar () {};
    namedFunctionExpr.name; // "bar"
    

    Also as you noted, you can’t change the value of this property, since in most implementations, it’s non-configurable, non-enumerable and non-writable:

    Object.getOwnPropertyDescriptor(function x(){}, 'name'); 
    /* logs:
    { 
      configurable: false,
      enumerable: false,
      value: "x",
      writable: false
    }
    */
    

    Remember, this property is non-standard and there are some implementations that don’t support it (e.g. all IE JScript versions do not support it)

    Now as @Felix suggest, I would like to add that this.name doesn’t have anything to do with your function’s name property.

    In your example, calling the obj function as a constructor (with the new operator), sets the this value to a newly created object, that inherits from your function’s prototype, and you are assigning a value to the name property to this new object.

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

Sidebar

Related Questions

hope this wasn't asked already, but I can't find an answer. I got a
wasn't too sure where to ask this. I am just trying to find which
Wasn't quite sure how to word this but let's say I've used ssh to
Okay I wasn't really sure how to word this question, but basically what I
This wasn't the question I was going to ask but I have unexpectedly run
I wasn't sure if there was any good way of doing this. But I
I wasn't sure how to word this exactly. But I have a model that
Already checked the Internet but I wasn't able to find it out :-
I wasn't sure what the best way to word this question is but basically
I wasn't really sure how to title this, but basically I am having 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.