Final Exam Deck #1 Flashcards

1
Q

What is the root prototype?

A

Object.prototype

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

What is returned for the following statement:
Object.getPrototypeOf( [ ] )

A

Array.prototype

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

What is returned for the following statement:
Object.getPrototypeOf( )

A

Object.prototype

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

How/Where are fields declared in a class?

A

Fields are declared within the constructor method

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

How can we add fields or methods to a class after the class has been created?

Ex: For the class “Car”, add a new field “sound”: “vroom”

A

We can add fields/methods to the prototype which are accessible by all instantiated object:

Car.prototype.sound = “Vroom”

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

How can we declare private fields within a class?

A

within the constructor function we do 3 things:

  1. use “let” to define a private field
  2. getter function
  3. setter function
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What does a subclass inherit from a superclass?

A

All its public fields and methods

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

Does a subclass inherit a superclass’s private members?

A

No, a child class does not inherit its parent’s private members

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

How are “extends” and prototypes related?

A

The “extends” keyword sets a prototype chain where the subclass’s prototype points to the parent class’s prototype

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

If we don’t define a constructor for a subclass what happens?

A

A default constructor is created where the first line calls the parents constructor using the “super” keyword

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

If we override the default constructor for a subclass what must we always do?

A

The first line of the constructor must always class the parents constructor using “super(parameter)”

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

Do arrow function have super?

A

No

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

What is the python equivalent of a JavaScript object?

A

A dictionary

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

If we try to access an object property that does not exist what happens?

A

That property gets added to the object

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

What happens when a binding is used without declaration? Ex: x=5

A

Its automatically added to the “global” object

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

What is the output of the following code? Does it return an error?

x=5
console.log(“Q1: “, x);
console.log(“Q2: “ global.x);

A

> > 5
5

14
Q

What does “use strict” do?

A

It prevents all un-declared variables from being added to the “global” object, requiring them to be declared.

15
Q

What is the output of the following code? Does it return an error? If so what is the error?

“use strict”
x=5
console.log(x);
console.log(global.x)

A

error: x is not defined

16
Q

What is the output of the following code? Does it return an error? If so what is the error?

“use strict”
x=5
console.log(x)
let x;

A

error: x is not initialized

17
Q

under “use strict”, what happens when we declare a variable with var?

A

Declarations are hoisted to the top of their scope and and initialized to “undefined”

18
Q

under “use strict”, what happens when we declare a variable with let?

A

Declarations are hoisted (defined) at their position in the code and initialized to undefined

19
Q

What is the output of the following code? Does it return an error? If so what is the error?

“use strict”
x=5
console.log(x)
var x;

A

5

20
Q

What is the output of the following code? Does it return an error? If so what is the error?

“use strict”
let x;
x=5
console.log(x)

A

5

21
Q

What does the following code log?

let values = {
num1: 5,
num2: 7
}

console.log(num3);

values.num3 = 10;
console.log(num3)

A

> > undefined

> > 10