1

are there any kind of difference between these two types of declarations or is it just a short-hand thing?

const bar = {
  foo: function() { return 0 },
}
const bar = {
  foo() { return 0 },
}
SoroushOwji
  • 123
  • 8

1 Answers1

0

An ES5 syntax looks like this:

const var = {
  foo: function() { return 0 }
}

ECMAScript 2015 allows developer to write a shorter syntax for method definitions on objects.

const bar = {
  foo() { return 0 }
}

Both are the same and the second syntax is a shorter and modern approach.

Ran Turner
  • 14,906
  • 5
  • 47
  • 53