I saw this code example online and when I run it it logs nothing on the console. I was expecting it to log "User Name" but its logs nothing. why is that so? Why "this" is not pointing to a newly created object? how JS determines the reference of this. What will be the behavior if I change normal function to arrow function and also if I put comple
function createUser() {
// create an object and return from function
return {
name: "User Name",
userRef: this,
};
}
// newly create object assigned to user variable
var user = createUser();
console.info(user.userRef.name);
Comments
Post a Comment