Q21. What will be the output of the following JavaScript code?
|
1 2 3 4 5 6 7 8 9 10 11 12 |
x = 9; var module = { x: 18, getX: function () { return this.x; } }; module.getX();//1 var getX = module.getX; getX(); //2 |
A21. The “module” is an object defined within “{….}”. It has a property “x” and a function “getX”. It is important understand the magic variable “this”.
|
1 2 3 |
module.getX(); //1 : returns 18 //... getX(); //2 : returns 9, why? |
Because in //2 case, … Read more ›...