Back to questions
JuniorTheoryCommon
What does the program print?
function diff(a, b) {
return a - b;
}
console.log(diff(10, diff(6, 2)));6
- Expecting
2: reading it as10 - 6 - 2from left to right. The inner call runs first and returns4, and only thendiff(10, 4)returns6. - Expecting
-14: thinking the arguments fill the parameters from the end. The first argument goes toaand the second tob, sodiff(6, 2)is4.
- What does
diff(diff(10, 6), 2)print, and why does it differ? - What would the program print if
diffhad noreturnline?