The "this" keyword Flashcards

Understanding what the 'this' keyword refers to in JS

1
Q

The ‘this’ keyword evaluates to the value of the … of the current execution context

A

The ‘this’ keyword evaluates to the value of the ThisBinding of the current execution context

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

The … site determines the …Binding

A

The callsite determines the ThisBinding

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

This is the … that owns the method in a method invocation

A

This is the object that owns the method in a method invocation

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

When invoking a method on an object, this becomes …

A

When invoking a method on an object, this becomes the object itself

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

In non-strict mode, a function’s internal ThisBinding defaults to …

A

In non-strict mode, a function’s internal ThisBinding defaults to the global object (the window object in a browser)

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

In regards to the ThisBinding, there is an important distinction between … invocation & … invocation

A

In regards to the ThisBinding, there is an important distinction between function invocation & method invocation

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

In regards to prototypal inheritance, the ThisBinding is still the context of the …, even when the prototype chain is queried

A

In regards to prototypal inheritance, the ThisBinding is still the context of the invocation, even when the prototype chain is queried

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

What is this automatically set to in a constructor function?

A

This is set to the newly created object

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

If we run a function in the global execution context, and console.log the this value inside the function, what will we see when we call the function?

A

We will see ‘window’ in a browser in non-strict mode.

We will see undefined in strict-mode.

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

In ES6 classes, methods called on a class use the … as the ThisBinding

A

In ES6 classes, methods called on a class use the object itself as the ThisBinding

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

Do arrow functions have their own ThisBinding?

A

No, arrow functions defer to the ThisBinding of their surrounding lexical context

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

What is the difference between call & apply?

A

Both call and apply take an object as their first argument, which sets the this value of a function. However, call takes a list of comma separated arguments as optional inputs, while apply takes an array of arguments as the second optional argument.

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

Name 3 methods that can explicitly change the this value of a function.

A

.call()
.apply()
.bind()

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

Every single JavaScript program is executed within an …

A

Execution Context

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

Every execution context has a …

A

ThisBinding

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

Is ‘this’ a reference to the function’s lexical scope?

A

No.