This site is mobile accessible. Press the "Tap Here" button to use a different font-size.
Smartphone icons created by Freepik - Flaticon
let myFunction = (a, b) => a * b;
It gets shorter! If the function has only one statement, and the statement returns a value, you can remove the brackets and the
keyword:In fact, if you have only one parameter, you can skip the parentheses as well:
With a regular function
represents the object that calls the function:// Regular Function: hello = function() { document.getElementById("demo").innerHTML += this; } // The window object calls the function: window.addEventListener("load", hello); // A button object calls the function: document.getElementById("btn").addEventListener("click", hello);
With an arrow function
represents the owner of the function:// Arrow Function: hello = () => { document.getElementById("demo").innerHTML += this; } // The window object calls the function: window.addEventListener("load", hello); // A button object calls the function: document.getElementById("btn").addEventListener("click", hello);
Remember these differences when you are working with functions. Sometimes the behavior of regular functions is what you want, if not, use arrow functions.
The following table defines the first browser versions with full support for Arrow Functions in JavaScript:
Chrome 45 | Edge 12 | Firefox 22 | Safari 10 | Opera 32 |
Sep, 2015 | Jul, 2015 | May, 2013 | Sep, 2016 | Sep, 2015 |
Eventually the navigation links, above, will be replaced by these (previous) and (next) buttons below.
JavaScript icons used in the buttons provided by ICONS8.COM. Smartphone icons created by Freepik - Flaticon