
Summations the multiple numbers
First way:
function sums(...numbers: number[]): number {
let sum = 0
for (const number of numbers) {
sum += number
}
return sum
}
console.log(sums(1, 2, 3, 4)) // 10
Second Way
function sum(...numbers: number[]): number {
return numbers.reduce((a, b) => a + b)
}
console.log(sum(5, 6, 4)) // 15
Related articles
10 Essential Steps for Migrating Your JavaScript Project to TypeScript in 2025
Discover the practical roadmap to seamlessly transition your JavaScript projects to TypeScript, enhancing type safety and developer productivity in 2025.
Crafting Dynamic Data-Driven User Interfaces with React and TypeScript
Learn how to effortlessly craft dynamic, data-driven user interfaces using React and TypeScript, enhancing your app's responsiveness and user experience.
Mastering Next-Gen API Security: JWTs with Node.js & TypeScript in 2025
Learn step-by-step how to enhance your API’s security using JWTs with Node.js and TypeScript, preparing your applications for the security demands of 2025.