How does the “this” keyword work in JavaScript?

JavascriptWeb DevelopmentFront End Technology

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>
raja
Published on 18-Jan-2018 12:27:03
Advertisements