different ways of declaring functions in javascript code example
Example 1: declare function javascript
function myFunction(var1, var2) {
return var1 * var2;
}
Example 2: js function
function myfunction() {
console.log("function");
};
myfunction()
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"));
Example 3: function js
function myFunc(param) {
return param
}
console.log(myFunc("Hello World"))