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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:41:46+00:00 2026-05-25T12:41:46+00:00

Consider the following code: var f = function() { return 10; } typeof f;

  • 0

Consider the following code:

var f = function() { return 10; }
typeof f;                         // returns "function"
f();                              // returns 10

var g = f;
g();                              // returns 10, obviously

var h = new f;
h;                                // console evaluates to f - ????
h();                              // Type error - called_non_callable
typeof h;                         // returns "object"

So, what is h here? The Chrome console seems to evaluate it as f, but it isn’t callable. What does it mean to “new” a function like this? How is h now related to f?

As an aside, these two lines appear to be equivalent:

var h = new f;
var h = new f();

What’s up with that?

  • 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-25T12:41:46+00:00Added an answer on May 25, 2026 at 12:41 pm

    The root of your confusion is the way that Chrome represents objects on its console.

    The expression new f() in your example is represented as ‘f‘ on the Chrome’s console output, but just as a mere “convenience” of this particular console, for example, logging the following object:

    ({constructor: function Foo(){}});
    

    Will show it represented as “Foo“. Basically the console tries to find a representation of which constructor your object is instance of.

    So, the console shows you f, but you are not logging the function, the new operator produces an object that inherits from f.prototype.

    You are returning 10 from the function, but since you call it with new, and the return type is a primitive, the value is discarded, the newly created object that inherits form f.prototype is returned.

    For example:

    var F = function () { return 10; };
    F.prototype.inherited = 'foo';
    
    var h = new F(); // the 10 returned is ignored
    h instanceof F; // true
    h.inherited;    // "foo"
    

    On the other hand, if you return an object from a constructor, the object instance that the new operator creates behind the scened (and inherits from the constructor’s prototype) will be lost, for example:

    var F = function () { return  {}; };
    F.prototype.inherited = 'foo';
    
    var h = new F(); // the empty object is returned
    h instanceof F; // false
    h.inherited;    // undefined
    

    Yes, new f; and new f(); are completely equivalent, although people recommend using the parentheses to add clarity to your code.

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

Sidebar

Related Questions

Consider the following code: var Widget = new Class({ Implements: [Options], options: { name
Consider the following base code: (function($) { $.fn.myPlugin = function(settings) { return this.each(function() {
Consider The Following Actionscript/Flex code: var LC:LocalConnection=new LocalConnection(); LC.addEventListener(StatusEvent.STATUS, Status); LC.send('A', 'SomeMethodName', 'Message'); LC.send('B',
Consider the following code: using (var ms = new MemoryStream()) { using(var writer =
Consider the following code snippet private void ProcessFile(string fullPath) { XmlTextReader rdr = new
Consider the following code: var sentences = [ 'Lorem ipsum dolor sit amet, consectetur
Consider following piece of code: declare @var bit = 0 select * from tableA
Consider the following code: procedure TForm1.PaintBox1Paint(Sender: TObject); var vRect : TRect; vFormat : TTextFormat;
Consider the following code: $(a).attr(disabled, disabled); In IE and FF, this will make anchors
Consider the following code: void Handler(object o, EventArgs e) { // I swear o

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.