What is the difference?


#1

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


#2

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.

https://www.codecademy.com/courses/learn-javascript-objects/lessons/objects/exercises/methods-es6?action=lesson_resume&course_redirect=introduction-to-javascript


#3

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


#4

I stand corrected, see answer below.


#5

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

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Method_definitions#Description

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