javascript-this Flashcards

1
Q

What is this in JavaScript?

A

the object that is currently executing the code.

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

What does it mean to say that this is an “implicit parameter”?

A

it is included as a paremeter even though it was not passed. It is implicit.

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

When is the value of this determined in a function; call time or definition time?

A

at call time

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

What does this refer to in the following code snippet?
var character = {
firstName: ‘Mario’,
greet: function () {
var message = ‘It's-a-me, ‘ + this.firstName + ‘!’;
console.log(message);
}
};

A

character object

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

Given the above character object, what is the result of the following code snippet? Why?
character.greet()

A

It’s-a-me, Mario!

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

Given the above character object, what is the result of the following code snippet? Why?
var hello = character.greet;
hello();

A

It’s-a-me, undefined!

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

How can you tell what the value of this will be for a particular function or method definition?

A

if there is no value to the left of the dot when the function is called, then by default, this will be the global window object.

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

How can you tell what the value of this is for a particular function or method call?

A

if there is no value to the left of the dot when the function is called, then by default, this will be the global window object.

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