1var x = myFunction(4, 3); // Function is called, return value will end up in x
2
3function myFunction(a, b) {
4 return a * b; // Function returns the product of a and b
5}
1function name(parameter1, parameter2, parameter3) {
2// what the function does
3}
4
1function myfunction() {
2 console.log("function");
3};
4
5myfunction() //Should say "function" in the console.
6
7function calculate(x, y, op) {
8 var answer;
9 if ( op = "add" ) {
10 answer = x + y;
11 };
12 else if ( op = "sub" ) {
13 answer = x - y;
14 };
15 else if ( op = "multi" ) {
16 answer = x * y;
17 };
18 else if ( op = "divide" ) {
19 answer = x / y;
20 };
21 else {
22 answer = "Error";
23 };
24 return answer;
25};
26
27console.log(calculate(15, 3, "divide")); //Should say 5 in console.
28//I hope I helped!
1function myFunction(var1, var2) {
2 return var1 * var2;
3}
43
5How to create a function in javascriptJavascript By TechWhizKid on Apr 5 2020
6function addfunc(a, b) {
7 return a + b;
8 // standard long function
9}
10
11addfunc = (a, b) => { return a + b; }
12// cleaner faster way creating functions!