Why does (a) not aqual any thing in this code ? function test( a , b = 3, c = 42) { return a + b + c; } console.log(test(5)); | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Why does (a) not aqual any thing in this code ? function test( a , b = 3, c = 42) { return a + b + c; } console.log(test(5));

Java script

30th Aug 2020, 9:56 AM
Ziyad Aldoumany
Ziyad Aldoumany - avatar
2 Answers
+ 3
a b and c are parameters ,here b and c are assigned default values in case user don't provide an argument for them but for the first input a we want a value from user so we aren't assigning ant default value to it , also if it was like a=4 passing 5 would override the previous value 4 and 5 would be the value for a
30th Aug 2020, 10:04 AM
Abhay
Abhay - avatar
+ 4
Please clarify your question what u asking about thia program output will be 50 . console.log(test(5) ) when here test function called so control will move to test function here b and c is also intilize so a will he automatically 5 after in return statement there is a+b+c means 5+3+42 total 50
30th Aug 2020, 10:10 AM
A S Raghuvanshi
A S Raghuvanshi - avatar