0

Please help me

What is the output of this code? function magic(a, b = 40) { return a + b; } console.log(magic(2));

22nd Nov 2019, 2:29 PM
Samir Bhandari
Samir Bhandari - avatar
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
19th Jul 2020, 3:31 PM
Мг. Кнап🌠
Мг. Кнап🌠 - avatar
+ 2
Output: 42 in console.log(magic(2)) the argument is passed to the first parameter (i.e. to a)
22nd Nov 2019, 2:42 PM
Мг. Кнап🌠
Мг. Кнап🌠 - avatar
+ 1
i am also don't understood please explain how 42
19th Jul 2020, 3:27 PM
Gandla Veeresh
Gandla Veeresh - avatar
+ 1
so if a=40 and b=2 so a+b=c it would 40+2=42
16th Dec 2020, 9:42 PM
Travis Troy Knutson
Travis Troy Knutson - avatar
+ 1
42
17th Dec 2020, 7:53 PM
Turikumana Isaie
Turikumana Isaie - avatar
0
i dont understand why it was 42. please explain
13th Jul 2020, 8:09 PM
jae early
jae early - avatar
0
42
23rd Jan 2021, 5:08 AM
Sriskantharaja Veniga
Sriskantharaja Veniga - avatar
0
42
7th Dec 2021, 11:43 AM
Md. Rakibul Islam
Md. Rakibul Islam - avatar