Computer >> Computer tutorials >  >> Programming >> Javascript

How does the “this” keyword work in JavaScript?


In JavaScript, this keyword is used as a reference to refer object or the subject of the code executed.

Example

<script>
   var college = {
      subject: "Maths",
      lecturer: "Amy",
         details: function () {
         document.write(this.subject);
      }
   }
</script>