ServiceNow Interview Question

3. What will be the console.log statements print const obj = { name: 'Billy', sing: function () { this.age = "20" console.log('a' , this); var anotherFunction = function() { this.age = "30" console.log('b', this); } anotherFunction(); } } obj.sing(); //first console will print properties of obj(name, age and sing) and second will print window object

Interview Answer

Anonymous

Jul 29, 2020

Ans 3. First console will print properties of obj(name, age and sing) since the this inside sing belongs to const obj and second will print window object becase function belongs to window so this inside that will print window object. a {name: "Billy", age: "20", sing: ƒ} b Window {parent: Window, opener: null, top: Window, length: 4, frames: Window, …}