function in js

Solutions on MaxInterview for function in js by the best coders in the world

showing results for - "function in js"
Henri
17 Apr 2018
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}
Lorenzo
29 Jan 2018
1function myFunction(){
2  document.write("Hello World!")
3}
4myFunction();
Alessandro
08 Sep 2018
1function name(parameter1, parameter2, parameter3) {
2// what the function does
3}
4
Till
06 Oct 2016
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!
Duane
06 Jan 2017
1var x = 10;
2
3function créerFonction1() {
4  var x = 20;
5  return new Function("return x;"); // ici |x| fait référence au |x| global
6}
7
8function créerFonction2() {
9  var x = 20;
10  function f() {
11    return x; // ici |x| fait référence au |x| local juste avant
12  }
13  return f;
14}
15
16var f1 = créerFonction1();
17console.log(f1());          // 10
18var f2 = créerFonction2();
19console.log(f2());          // 20
Antonia
15 Jan 2018
1
2function
3name(parameter1, parameter2, parameter3) {
4
5    // code to be executed
6
7}
8