Arrow Functions in ECMA Script 6:
Arrow functions allow us to store functions as Constants and Variables.
The following piece of code allows us to save an arrow function that squares 10 as a const:
const square_function = (x)=>x*x;
We can better understand what is being expressed in the above statement by saying it aloud in English:
square_functionis an identifier, which represents an address in memory, and which names the data contained within this piece of memory, and which in this instance is a
constant– i.e. its value cannot change at runtime – which contains a function that takes a parameter,
x, and which applies a squaring operation to this parameter.
When it comes to the mathematics of functions, it is more proper to say that a function is applied to a parameter.
Below is a button that employs the attribute onclick so as to square 10 and then to print the result or square to the screen:
When the above button is pressed, the above-described code causes the number 100 to be printed to the screen.