-6

In typescript as well as in ES6 why we are using =>, when we need to use this one actually.how it makes differ from older version of javascript.

Shamil
  • 727
  • 1
  • 9
  • 17
  • I recommend watching this video: https://www.youtube.com/watch?v=6sQDTgOqh-I&t=2s – eol Jan 09 '17 at 10:19

1 Answers1

0

The arrows are used in ecma script 6 to create something called arrow functions it is used to create functions that are normally short , also it has some differences between the standard function syntax where you can not use the this keyword the same way you do with regular functions

(singleParam) => { statements }

i also recorded a youtube video a while ago explaining what is an arrow function and how you can use them.

Fady Sadek
  • 1,091
  • 1
  • 13
  • 22
  • 1
    *"it is used to create functions that does not have a lot of things going on inside it"* - Except they can be used to created functions of any length. And perhaps, more important, is what `this` will be inside the function. – nnnnnn Jan 09 '17 at 10:04
  • 1
    that's an over-simplistic representation of the syntax. ES6 arrow functions can take _multiple parameters_, the parentheses may be omitted if there's only a single parameter, and you can supply a single expression instead of a block, in which case the result of the expression is implicitly returned, e.g, `x => 2 * x` is a perfectly valid arrow function, as would be `(x, y) => Math.pow(x, y)` – Alnitak Jan 09 '17 at 10:05
  • I explained this in the video i pasted but the guy seemed a little bit confused so i think there is nothing wrong with simplifying things a little bit and i also pasted the link of the video if he wanted to know more and i edited the answer thanks to you guys – Fady Sadek Jan 09 '17 at 10:12