SHARE
Facebook X Pinterest WhatsApp

JavaScript Function Arguments ES6 Style!

Written By
thumbnail
Rob Gravelle
Rob Gravelle
May 22, 2017

TC39 (Ecma Technical Committee 39), the committee that evolves JavaScript, released the ECMAScript 6 (ES6) spec in June of 2015. It contains a ton of new features, including Arrows, Tail Calls, Object Literals, and Destructuring Assignments. One area that received a lot of updates was function arguments. These were enhanced with default values, rest parameters, and the spread operator. In today’s tutorial, I’ll go over each of these features and present examples that illustrate usage.

Using ES6 Syntax

Since 2015, browser vendors’ adoption of ES6 has been somewhat spotty. Hence, most browsers only support some ES6 features: the new Microsoft Edge browser has over eighty percent ES6 support, and FF/Chrome are around 50-60%. Ideally, you would want to test for specific features and employ some sort of shiv if a feature is not supported. Unfortunately, Modernizr-style feature testing for syntax doesn’t work because the ES6 syntax fails JS compilation in pre-ES6 compliant browsers before it runs, so try…catch blocks are useless.

For that reason, your best bet is to use a transpilation tool. These are a special kind of preprocessor — the likes of which include CoffeeScript (JavaScript), Sass (CSS), and HAML (HTML) — that compiles ES6 code into ES5 code, so that it will run on non- or semi- compliant browsers. The three most popular ones right now are Traceur, Babel, and TypeScript. I personally recommend Babel because supports the greatest number of ES6 features. Moreover, it also supports JSX by React, which is a powerful UI framework, and enjoys a vibrant and growing community of development and support.

Using Babel

Recommended for you...

The Revolutionary ES6 Rest and Spread Operators
Rob Gravelle
Aug 23, 2022
Ahead of Time (AOT) Compilation in Angular
Tariq Siddiqui
Aug 16, 2022
Converting a JavaScript Object to a String
Rob Gravelle
Aug 14, 2022
Understanding Primitive Type Coercion in JavaScript
Rob Gravelle
Jul 28, 2022
HTML Goodies Logo

The original home of HTML tutorials. HTMLGoodies is a website dedicated to publishing tutorials that cover every aspect of being a web developer. We cover programming and web development tutorials on languages and technologies such as HTML, JavaScript, and CSS. In addition, our articles cover web frameworks like Angular and React.JS, as well as popular Content Management Systems (CMS) that include WordPress, Drupal, and Joomla. Website development platforms like Shopify, Squarespace, and Wix are also featured. Topics related to solid web design and Internet Marketing also find a home on HTMLGoodies, as we discuss UX/UI Design, Search Engine Optimization (SEO), and web dev best practices.

Property of TechnologyAdvice. © 2025 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.