es6 method definition syntax 1

es6 method definition syntax

const obj = {
  foo() {
    return 'bar';
  }
};

console.log(obj.foo());
// expected output: "bar"

Here is what the above code is Doing:
1. We create an object called obj.
2. We add a method to obj called foo.
3. We call the foo method on obj.

Similar Posts