JSFiddle - React, Tailwind, and code Playground

by matox

JavaScript

'use strict';

const user = {	// A
  name2: "Bob",
  printName: function () {	// B
    setTimeout(function () {	// C
    	console.log(this);
      console.log(this.name2);
    });
  },
};

user.printName();

/*
	QUESTIONS:
  - Why is lexical scope of "C" not inherited from "B"?
  	- Is it because of "setTimeout" or because we use anonymous function?
*/