0
Please help me
What is the output of this code? function magic(a, b = 40) { return a + b; } console.log(magic(2));
8 Respostas
+ 6
function magic(a,b=40)
This is a function which has two parameters (a,b) where the second parameter b is set with default value of 40. Which means while calling the magic function I can pass only one argument or both arguments.
console.log(magic(2)) so here we just passed 2 as the argument, since we already have a value for "b parameter"
so 2+42 returned by the function as 42
+ 2
Output: 42
in console.log(magic(2)) the argument is passed to the first parameter (i.e. to a)
+ 1
i am also don't understood please explain how 42
+ 1
so if a=40 and b=2 so a+b=c it would 40+2=42
+ 1
42
0
i dont understand why it was 42. please explain
0
42
0
42