0

How does nested functions work in javascript? Any examples?

Nested functions in javascript

10th Feb 2017, 2:42 PM
maik
maik - avatar
1 Antwort
+ 2
Nested functions are simply functions in a function. You declare them inside a function block. function total(array) { function isNumber(o) { return typeof o === "number"; } var sum = 0; for (var i = 0; i < array.length; i++) { if (isNumber(array[i]) { sum += array[i]; } } return sum; } total([5, 7, "6", 2]); // returns 14 Here `isNumber` is nested inside the function `total`.
10th Feb 2017, 8:25 PM
John
John - avatar