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!
1// Named function
2function add(x: number, y: number): number {
3 return x + y;
4}
5
6// Anonymous function
7let myAdd = function (x: number, y: number): number {
8 return x + y;
9};