what are functions in javascript code example

Example 1: js function

function name(parameter1, parameter2, parameter3) {
// what the function does
}

Example 2: javascript function

// variable:
var num1;
var num2;
// function:
function newFunction(num1, num2){
	return num1 * num2;
}

Example 3: define function in javascript

/* Declare function */
function myFunc(param) {
  // Statements 
}

Example 4: 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 5: js function

function myfunction() {
  console.log("function");
};

myfunction() //Should say "function" in the console.

function calculate(x, y, op) {
  var answer;
  if ( op = "add" ) {
    answer = x + y;
  };
  else if ( op = "sub" ) {
    answer = x - y;
  };
  else if ( op = "multi" ) {
    answer = x * y;
  };
  else if ( op = "divide" ) {
    answer = x / y;
  };
  else {
    answer = "Error";
  };
  return answer;
};

console.log(calculate(15, 3, "divide")); //Should say 5 in console.
//I hope I helped!

Example 6: javascript functions

function sayHelloTo(to) {
  alert(`Hello ${to}`);
}
sayHelloTo('World from Grepper')