Horje Website
JavaScript ES6 Spread Operator – JavaScript Code

JavaScript ES6 Spread Operator

JavaScript ES6 Spread Operator - JavaScript Code


 
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>JavaScript ES6 Spread Operator</title>
  6. </head>
  7. <body>
  8. <script>
  9. function addNumbers(a, b, c) {
  10. return a + b + c;
  11. }
  12. let numbers = [5, 12, 8];
  13. // ES5 way of passing array as an argument of a function
  14. document.write(addNumbers.apply(null, numbers)); // 25
  15. document.write("<br>");
  16. // ES6 spread operator
  17. document.write(addNumbers(...numbers)); // 25
  18. </script>
  19. </body>
  20. </html>



Try Your Self ->



Published:
September 12, 2020
Author:
admin
Category:
JavaScript Example, Javascript Source Code
Views:
11

This article was posted in JavaScript Example, Javascript Source Code and tagged , , . Bookmark the permalink. Follow comments with the RSS feed for this post.Post a Comment or leave a trackback: Trackback URL.

Leave a Reply

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

 

Horje © 2011 - 2022