What is a constructor in programming?

727 viewsOtherTechnology

I am still trying to wrap my head around the concept I learned in class a while ago. We learned briefly about constructors in JavaScript. Can someone please ELI5? Thank you!

In: Technology

18 Answers

Anonymous 0 Comments

Constructors are just instructions for set up:

Imagine you had a box labeled “cars”  you can reach into that box and magically pull car after car out.  But what state is it in?  Lights on or off? Doors open? Locked?

A constructor tells the magic making the cars how to initialize it: doors closed, lights off, gas tank empty etc.

You are viewing 1 out of 18 answers, click here to view all answers.