Why 'this' is referring to Window object in below code snippet?
Why 'this' is referring to Window object in below code snippet? Can someone help me understand why the below code prints Inside splitName function = [object Window] Why 'this' is referring to Window object? let emp = { fName: '', lName: '', setName: function(name) { console.log("Inside setName function = " + this) let splitName = function(n) { console.log("Inside splitName function = " + this) let nameArr = n.split(' '); this.fName = nameArr[0]; this.lName = nameArr[1]; } splitName(name); } } emp.setName('ABC DEF'); console.log(window.fName); Because splitName(name); has no calling context – CertainPerformance Jul 2 at 3:39 splitName(name); Also because it is run in non-strict mode, otherwise it wo...