// This approach of defining a function is called "**Function Expression".**
let sayHi = function() {
  console.log("Hello");
};
console.log(sayHi); // Shows the function code.
sayHi(); // Hello

Local & Global Variables

Parameters

function showMessage1(from, text) {
  // If text is falsy then text gets the "default" value.
  text = text || 'no text given';
}

function showMessage2(from, text = "no text given") {
  alert(from + ": " + text);
}

function showMessage3(from, text = anotherFunction()) {
  // anotherFunction() only executed if no text given its result becomes the value of text.
}

Arrow Functions

let sayHi = () => alert("Hello!");
let sum = (a, b) => a + b;
let sum = (a, b) => {  // the curly brace opens a multiline function
  let result = a + b;
  return result; // if we use curly braces, use return to get results
};
let double = n => n * 2;

Rest Parameters