+ 1
JavaScript "I would like to understand why the output is 7"
function calc(j,p) { j *= p++; return j+p; j-= p; } alert(calc(2,2)); output is 7
2 Réponses
+ 17
First of all.. j = j * p++... j = j * p, which makes j = 4.. But because ++ is in the end is incremented after assignment so p is 3.. Then the function returns 4 + 3 which is 7.. Everything after return is ignored...
+ 1
thanks