You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
### 7. What would be the output of following code ?
3425
+
3426
+
```javascript
3427
+
functiongetName1(){
3428
+
console.log(this.name);
3429
+
}
3430
+
3431
+
Object.prototype.getName2= () =>{
3432
+
console.log(this.name)
3433
+
}
3434
+
3435
+
let personObj = {
3436
+
name:"Tony",
3437
+
print:getName1
3438
+
}
3439
+
3440
+
personObj.print();
3441
+
personObj.getName2();
3442
+
```
3443
+
3444
+
1. undefined undefined
3445
+
2. Tony undefined
3446
+
3. undefined Tony
3447
+
4. Tony Tony
3448
+
3449
+
Answer: 2) Tony undefined
3450
+
3451
+
Explaination: **getName1()** function works fine because it's being called from ***personObj***, so it has access to *this.name* property. But when while calling **getnName2** which is defined under *Object.prototype* doesn't have any proprty named *this.name*. There should be *name* property under prototype. Following is the code:
0 commit comments