Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

227
Views
difference between constructor and class in javascript

what is the const halley=... referring to?Is it storing the new created object?or is itself a new object?and what does the Dog after the new keyword means?Class or constructor?

class Dog {
 constructor(name) {
   this.name = name;
   this.behavior = 0;
 } 
}

const halley = new Dog('Halley'); // Create new Dog instance
console.log(halley.name);
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

In JavaScript, a constructor function is a function designed for use with the new keyword to create instances of a type of object. Typically you would assign something to its prototype property to define properties that would be inherited by the instance.

The class keyword is a newish feature that allows the creation of a constructor function and its associated prototype using syntax which looks more like traditional OO syntax in other programming languages.

The value assigned to Dog is both a class and a constructor function.

about 4 years ago · Juan Pablo Isaza Report

0

This part define the class. A class is like a recipe to make objects. A constructor is a method of a class that define how to create new instances (objects):

class Dog {
 constructor(name) {
   this.name = name;
   this.behavior = 0;
 } 
}

This part create an instance (object) of the class Dog:

const halley = new Dog('Halley');
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!