What is the difference?


Can anyone explain, what is wrong with this? I mean, they are both functions, right?


In 2015, a new version of JavaScript (ES6) was introduced with additional methods and new syntax. One of the syntax changes impacted how you can create methods. The new version of JavaScript supports the old method syntax because many JavaScript developers still use it.

The new method syntax (see below) doesn’t require arrow syntax or a colon ( : ) with the function keyword.



‘‘doesnt require’’ or doesnt work at all?


I stand corrected, see answer below.


There are two ways to define methods, es5 and es6, see the documentation:


using the arrow function syntax won’t work for method, this keyword won’t get the correct scope, so it won’t work