You can export functions and values from a module by either using module.exports: module . exports = { value1 , function1 } or by using exports: exports . value1 = value1 exports . function1 = function1 So what's the difference? Exporting values with just the exports keyword is a quick way to export values from a module. You can use this keyword at the top or bottom, and all it does is populate the module.exports object. But if you're using exports in a file, stick to using it throughout that file. Using module.exports is a way of explicitly specifying a module's exports. And this should ideally only exist once in a file. If it exists twice, the second declaration reassigns the module.exports property, and the module only exports what the second declaration states. So as a solution to the previous code, you either export like this: // ... exports . value1 = value1 // ... exports . function1 = function1 ...
console.log('sum(1)(2)(3)(4)..( n)()'); // Solution 1: let sum = function (a) { return function (b) { if (b) { return sum(a + b); } return a; } } let result = sum(1)(2)(3)(4)(5)(); console.log(result); // 15 // Solution 2: let sum = (a) => (b) => (b) ? sum(a+b) : a; let result = sum(1)(2)(3)(4)(5)(); console.log(result); // 15