1// (param1, param2, paramN) => expression
2
3// ES5
4var multiplyES5 = function(x, y) {
5 return x * y;
6};
7
8// ES6
9const multiplyES6 = (x, y) => { return x * y };
10
1// Regular function, called explicitly by name .aka “named function”
2function multiply(a, b){
3 var result = a * b;
4 console.log(result);
5}
6multiply(5, 3);
7
8// Anonymous function stored in variable.
9// Invoked by calling the variable as a function
10// Anonymous functions don't have a name,
11// so the parentheses appears right after “function” keyword.
12var divided = function() {
13 var result = 15 / 3;
14 console.log("15 divided by 4 is " + result);
15}
16divided();
17
18// Immediately Invoked Function Expression.
19// Immediately invoked function expressions are anonymous functions
20// with another parentheses pair at the end to trigger them,
21// all wrapped inside parentheses.
22// Runs as soon as the browser finds it:
23(function() {
24 var result = 20 / 10;
25 console.log("20 divided by 10 is " + result);
26}())
27