JS Interview Question: Difference between: function Person(){}, var person = Person(), and var person = new Person()?

There are different ways (not to be exact) we can use functions in JavaScript, but with the given code below highlights important differences on how functions work.

function Person() {}

Function Declaration
Code above declares a function statement (statements perform an action) but does not execute, however, it does get registered into the global namespace.

var person = Person()

Function Expression
A variable ‘var person’ has been defined and contains a value reference to a Person function. Any JavaScript Expressions (including Function Expressions) always returns a value. This may also be an Anonymous function if no name has been assign to a function but wrapped in parenthesis to be interpreted as an expression.

var person = new Person()

Function Constructor
By adding the keyword ‘new’. We are instantiating a new object of the Person class constructor. A function declaration is just a regular function unless it has been instantiated, it then becomes a class constructor.


If you are looking for a platform to develop your clients’ website, check out my SAAS platform https://ecompurpl.com

EcomPurpl.com is the all-in-one solution for anyone looking to create a website. Templates, E-Commerce, Hosting, Galleries, Booking & Appointments, CRM, 24/7 support, and integration of your app are all included.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
RLyn Ben

RLyn Ben

Software Engineer / Front-End Dev. Currently resides in Las Vegas. https://ecompurpl.com