Arrow functions in ECMAScript 608 Jul 2016
I think that an arrow functions are one of the best features of ECMAScript 6, excluding
class-es and OOP programming at all.
It has really very helpful and useful syntax for scripting language. So let’s check it out:
How did it look in ECMASript 5?
I love the syntax of arrow functions in ECMAScript 6! I always asked myself a question why do I need to write word ‘function’ all the time. And now I don’t have to.
Let’s see some examples:
This is simple function that returns square of number passed as a parameter. Isn’t it pretty?
In ECMAScript 5 it should be written like this:
But to understand where the new syntax is really helpful, let’s look at injected functions:
Don’t you see that ECMAScript 6 is more about program you wrote, not about syntax of it!
* In last example in ECMAScript 6 I used a block-scope, in ECMAScript 5 only function was block scoped. Read more about block-scopes in ECMAScript 6 here: