Rest Operator tutorial in Advance JavaScript

 <!DOCTYPE html>

<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, shrink-to-fit=no">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Rest Operator tutorial Advance JavaScript</title>
    <link rel="stylesheet" href="">
</head>

<body>
    <script>
        //"..." is Rest Operator and Rest Operator will convert values(Here below values are 20,30,40...) in Array.
        //"..." is Spread Operator and Spread Operator will Spread Array Values .
        //Rest Operator is used at the time of function declaration and Spread Operator is used at the time of function Calling.
        //We can use Spread Operator "..." with Arrays as well as Object also.
        function sum(name, course, ...args) {
            console.log(arguments);

            document.write(`Hello ${name} of ${course} : `);

            let sum = 0;
            for (let i in args) {
                sum += args[i];
            }
            document.write(sum + "<br>");
        }
        sum("World", "BTech", 20, 30, 40);
        sum("Ram Kumar", "MBA", 55, 44, 11);
        sum("Anil Kapoor", "MTech", 11, 22, 33, 44, 55, 66);
    </script>
</body>

</html>



Comments

Popular posts from this blog

Generators tutorial in Advance JavaScript

Document Object Module DOM querySelector and querySelectorAll tutorial in JavaScript

Find Even and Odd Numbers with Loops tutorial in JavaScript