Javascript-this Flashcards

1
Q

What is this in JavaScript?

A
  1. implicit parameter –> this is pointing to an object we want to look at.
    key word that contains a value defined at a call time.
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
  1. value that is available in function defintion even though we didn’t put it in a parameter
  2. NOT explicitly written in function definition. and it is available in function definition.
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

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?

A

There is not definition because we are not in call yet, only in defition time
referring to 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?

A

The result will be the string value Its me mario. we are calling from character.

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?

A

undefined! because window doesn’t have an object!

this is not gear towards to character anymore.

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

You wouldn’t be able to tell because function is not called yet.
by default it will refer to the default 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

you look at the object that is on the left

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