Answers for "types of js functions"

2

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!
Posted by: Guest on June-22-2020
0

types of functions in javascript

Named function
Anonymous function
Immediately invoked function expression.
Posted by: Guest on January-19-2021
0

types of js functions

//Declaration Function
function compute(){}
//Expression Function
const compute = function() {};
//Arrow Syntax
const compute = () => {};
//Functions via Methods
const obj = {
	compute(){}
}
//Functions as Objects
function sum(x,y){
  return x + y;
}
//Return object from function
function getEmptyObject(){
  return {};
}
//Return function from function
function createFunction(x){
  return function(){}
}
Posted by: Guest on April-01-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language