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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T21:20:10+00:00 2026-06-12T21:20:10+00:00

Possible Duplicate: JavaScript: var functionName = function() {} vs function functionName() {} I would

  • 0

Possible Duplicate:
JavaScript: var functionName = function() {} vs function functionName() {}

I would like to know if there is some hidden difference between the two following constructor function:

var Person = function(name){
     this.say=function(){
         console.log(name);
     }
}

and this one:

function Person(name){
         this.say=function(){
             console.log(name);
         }
  }

suppose we are always going to write:

var x = new Person('xxxxx');
x.say();

It appear to be the same in order to me, but I’m really green in javascript and I would like to know if some form is wrong and if there is some best practices to follow.

  • 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-12T21:20:11+00:00Added an answer on June 12, 2026 at 9:20 pm

    There is no difference as far as constructors are concerned. All functions in JavaScript can be called as constructors (whether they throw errors or not is a different issue altogether).

    The difference is between how the functions are declared.

    The first declaration is as a variable that requires execution. The second declaration is as a function that is hoisted.

    var foo and function foo statements in JavaScript get hoisted to the top of their closing scope (nearest function parent). This means that:

    (function () { //closure for scope
      doStuff();
      var foo = bar;
    }());
    

    is actually:

    (function () {
      var foo;
      doStuff();
      foo = bar;
    }());
    

    functions react similarly:

    (function () {
      doStuff();
      function foo() {
        bar = baz;
      }
    }());
    

    is the same as:

    (function () {
      function foo() {
        bar = baz;
      }
      doStuff();
    }());
    

    This distinction is important because a function declared in a variable isn’t accessible until after it’s been declared:

    (function () {
      foo(); //this doesn't work and will result in an error
      var foo = function () {
        alert('works');
      };
    }());
    

    whereas a function is accessible as long as it’s somewhere within scope:

    (function () {
      foo(); //works!
      function foo() {
        alert('works!');
      }
    }());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: JavaScript: var functionName = function() {} vs function functionName() {} AFAIK, there
Possible Duplicate: JavaScript: var functionName = function() {} vs function functionName() {} There are
Possible Duplicate: Javascript: var functionName = function() {} vs function functionName() {} Is there
Possible Duplicate: JavaScript: var functionName = function() {} vs function functionName() {} There are
Possible Duplicate: The difference between the two functions? (“function x” vs “var x =
Possible Duplicate: JavaScript: Why the anonymous function wrapper? I would like to ask you
Possible Duplicate: JavaScript: var functionName = function() {} vs function functionName() {} What is
Possible Duplicate: JavaScript: var functionName = function() {} vs function functionName() {} Suppose we
Possible Duplicate: Javascript: var functionName = function() {} vs function functionName() {} Way 1:
Possible Duplicate: JavaScript: var functionName = function() {} vs function functionName() {} What is

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.