/*
Function Declaration vs Function Expresssion vs Arrow Function
function declaration:
*/
function sayName(){
console.log('My name is', name);
}
/*
function expresssion
*/
const sayName = function (){
console.log('My name is', name);
}
/*
arrow function: remove 'function' text and then add an arrow; if it has one arg, you can omit (); if body is one line long you can omit the curly braces and 'return' text.
*/
const sayName = () => {
console.log('My name is', name);
}
const square = (x) => {
return x * x;
}
/* or */
const square = x => x * x;
//---------------------------------------------
//These are all functionally the same:
//Function Declaration
function divide1(a, b) {
return a / b;
}
//Function Expression
const divide2 = function(a, b) {
return a / b;
}
//Arrow Function Expression
const divide3 = (a, b) => {
return a / b;
}
//Arrow Function Expression - concise
const divide4 = (a, b) => a / b;