Review my understanding of the 'this' keyword

This is roughly accurate, just be careful with words like “always” :slight_smile:
For example:

console.log(this);

Here we call log function of the console, so this has to refer to console, right? :wink:

After playing a bit with this I’ve actually realized that JS forces it to be an object-like, by running Object(value) on things you’re trying to assign to this - I’m pretty sure there is some reason behind it. So:

function a() {
  return this;
};

a(); // Window (global object);
new a(); // {}

const b = a.bind(42);
b.name; // "bound a"
b(); // Number { 42 } (an object)
b.call(window); // Number { 42 } (bound values are immutable)
new b(); // {} (new keyword ignores tightly bound this)

const c = a.bind(null);
c(); // Window (global object - this cannot be null)

const d = a.bind(undefined);
d(); // Window (same story as with null)

So my updated answer to your question #5 would be this cannot be undefined whatsoever.

If you’re trying to access this outside function it will normally point to current context - Window object in console, but also a module in Node JS module (not a global object). If we’re talking about browser’s console, the exception to this would be class, as inside the ES6 class this would refer to instance:

class This {
  print = () => console.log(this); // we're using arrow function to access outer scoped this
}

const t = new This();
t.print(); // This {}

// And to prove that THIS is enclosed:
const w = t.print;
w(); // This {}

So as you can see “always have the value of the global object” is highly inaccurate :slight_smile: