HTML CSS AND JS CODE FOR Function to Add an Arbitrary List of Parameters

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Sum Function</title>
</head>
<body>
    <script>
        function sum(...args) {
            return args.reduce((acc, val) => acc + val, 0);
        }

        console.log(sum(1, 2)); // Output: 3
        console.log(sum(1, 3, 4)); // Output: 8
    </script>
</body>
</html>
JavaScript

Leave a Reply

Your email address will not be published. Required fields are marked *


error: Content is protected !!
Scroll to Top
MacroNepal
Verified by MonsterInsights