function sum() { var sum = 0; for (var i = 0; i < arguments.length; i++) { sum += arguments[i]; } return sum; } var a = sum(5, -5, false, '-5', 5); console.log(a);
0+5 = 5 5 + -5 = 0 0 + false = 0 // true converts in to 1 and false into 0. 0 + '-5' = '0-5' // number + string converts to string '0-5' + '5' = '0-55'
Login in to like
Login in to comment
typeof arguments === 'object'
2018 Mar 23, 9:36:27 AM
@KP1976 thanks! improved explanation
2017 Dec 5, 3:27:18 PM
First is 0+5 = 5
2017 Nov 29, 11:00:40 AM
or Read more about JavaScript Quizzes
Login in to like
Login in to comment