Constructor, operator "new" Flashcards

1
Q

Constructor functions technically are regular functions. There are two conventions though:

A

They are named with capital letter first.

They should be executed only with “new” operator.

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

When a function is executed with new, it does the following 3 steps

A

A new empty object is created and assigned to this.

The function body executes.

The value of this is returned.

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

Usually, constructors do not have a return statement. Their task is to write all necessary stuff into this, and it automatically becomes the result.

But if there is a return statement, then the rule is simple:

A

If return is called with an object, then the object is returned instead of this.

If return is called with a primitive, it’s ignored.

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

Constructor functions should only be called using ______

A

new

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

We can use constructor functions to make ______

A

multiple similar objects.

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