Back to questions
JuniorTheoryCommon
What does the program print?
function add(a, b) {
return a + b;
}
console.log(add(1), add(1, 2, 3));NaN 3
- Expecting a missing argument to count as
0: the parameterbisundefined, and1 + undefinedisNaN, soadd(1)printsNaN. - Expecting the extra argument
3to be added too:addhas only two parameters, so the third argument is ignored andadd(1, 2, 3)is3.
- How would you change
addso thatadd(1)prints1? - What does a function without a
returnstatement give back when it is called?