Iulian Barbu Iulian Barbu - 15 days ago 5
Javascript Question

What means => used in this way in Javascript syntax?

I searched something on SO and run into this, which is a way to retrive a file from your local computer and use it in browser, with AngularJS.

this.http.get(<path_to_your_json_file>)
.success((data) => console.log(data));


I wonder what this JavaScript syntax could mean:


(data) => console.log(data)


I don't know if is something AngularJS specific, but I mostly doubt so. Do you know more interesting tweaks which are no so common in daily use of JavaScript?

Answer

This is an arrow function: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions.

Arrow functions were introduced into JavaScript with ES2015.

Writing (data) => console.log(data) is equivalent to writing function (data) { console.log(data); }.

Comments