Skip to main content

Posts

Showing posts from August, 2017

Javascript ECMAScript6 New Feature

Extended Parameter Handling Another nice set of features introduced in ES6 is the extended parameter handling. These provide a very nice set of idioms that bring us very close to languages like C# or Java. Default parameter values and optional parameters Default parameters allow your functions to have optional arguments without needing to check arguments.length or check for undefined. Let’s take a look at what that might look like: let greet = (msg = 'hello', name = 'world') => {   console.log(msg,name); } greet(); greet('hey'); Looking at the preceding code, you can see that we are using the new fat arrow (=>) syntax as well as the new let keyword. Neither of those are necessary for this example, but I added it to give you more exposure to the new syntax. Running the preceding code produces the following result: hello world hey world  Rest parameter Handling a function with a variable number of arguments is always t