javascript constructors Flashcards

1
Q

EXAMPLE:
function Car(make, model, year) {
this.make = make;
this.model = model;
this.year = year;
}

const car1 = new Car(‘Eagle’, ‘Talon TSi’, 1993);

console.log(car1.make);
// Expected output: “Eagle”

SYNTAX:
new constructor
new constructor()
new constructor(arg1)
new constructor(arg1, arg2)
new constructor(arg1, arg2, /* …, */ argN)

ANOTHRE EXAMPLE:
function Car(make, model, year) {
this.make = make;
this.model = model;
this.year = year;
}

create object (for the example):
const myCar = new Car(“Eagle”, “Talon TSi”, 1993);

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What does the new operator do?

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What property of JavaScript functions can store shared behavior for instances created with new?

A

their prototype

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What does the instanceof operator do?

A

checks if a constructor function matches the one specified

How well did you know this?
1
Not at all
2
3
4
5
Perfectly