write function()= in js code example

Example 1: functions in javascript

function myFunction(var1, var2) {
  return var1 * var2;
}
3
How to create a function in javascriptJavascript By TechWhizKid on Apr 5 2020
function addfunc(a, b) {
  return a + b;
  // standard long function
}

addfunc = (a, b) => { return a + b; }
// cleaner faster way creating functions!

Example 2: js function

function MyFunction() {
	/* Function Here */
}

Example 3: javascript function

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
// FUNCTION DECLARATION (invoking can be done before declaration)
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
function calcAge1(birthYear) {
   return 2037 - birthYear;
}
const age1 = calcAge1(1991);

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
// FUNCTION EXPRESSION (invoking canNOT be done before declaration)
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
const calcAge2 = function (birthYear) {
   return 2037 - birthYear;
}
const age2 = calcAge2(1991);

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
// ARROW FUNCTION (generally used for one-liner functions)
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
const calcAge3 = birthYear => 2037 - birthYear;
const age3 = calcAge3(1991);
console.log(age3);