This site is mobile accessible. Press the "Tap Here" button to use a smaller font-size.

Smartphone icons created by Freepik - Flaticon

JavaScript "this"

This example demonstrate that in a regular function, the "this" keyword represents different objects depending on how the function was called.

Click the button to execute the "hello" function again, and you will see that this time "this" represents the button object.

let hello = "";

hello = function() {
  document.getElementById("demo").innerHTML += this;
}

//The window object calls the function:
window.addEventListener("load", hello);

//A button object calls the function:
document.getElementById("btn").addEventListener("click", hello);