How to use arrow functions used as methods in JavaScript?

Fat arrow function as the name suggests helps in decreasing line of code. The syntax => shows fat arrow. This also avoids you to write the keyword “function” repeatedly. Arrow functions are generally used for a non-method function. Let’s see how to use arrow functions used as methods:


You can try to run the following code to implement arrow functions used as methods

Live Demo

<!DOCTYPE html>
         'use strict';
         var ob1 = {
            val1: 75,
            val2: 100,
            x: () => document.write(this.val1, this),

            y: function() {
               document.write("<br>"+this.val1, this);

            z: function() {
               document.write("<br>"+this.val2, this);

Updated on: 07-Jan-2020


Kickstart Your Career

Get certified by completing the course

Get Started