Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript Object-Oriented JavaScript (2015) Introduction to Methods Different Kinds of Objects

Difference between regular functions and constructor functions

How can I differentiate normal functions vs constructor functions?

2 Answers

Steven Parker
Steven Parker
231,269 Points

It won't always be obvious except by usage.

The best evidence of a constructor function is when you see it being used to create an instance with the "new" keyword. Other than that, there's no certain difference, but here's some things that might be clues:

  • by convention, constructor function names start with capital letters
  • inside a constructor function, you may see properties being set using "this"
  • you may also see methods being created using "this" and anonymous functions
  • a constructor wont return anything

Thanks Steven, as always you are here to help.

Greg Schudel
Greg Schudel
4,090 Points

a constructor wont return anything

if it doesn't return anything how can you use it? I thought the whole point was being able to make a variety of similar instances of the object it's calling. Kinda like a factory drone on a conveyer line.

Steven Parker
Steven Parker
231,269 Points

The constructor function doesn't return anything, but the new keyword returns the new object.