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
Arrow functions I think that an arrow functions are one of the best features of ECMAScript 6 , excluding class -es and OOP programming at all. It has really very helpful and useful syntax for scripting language. So let’s check it out: Syntax //Function with no parameters: () => { statements } ] //Function with single parameter: singleParam => { statements } //Function with one and more parameter: (param1, param2, …, paramN) => { statements } //Function with simple return statement: n => n * 2 How did it look in ECMASript 5? //Function with no parameters: function () { statements } //Function with single parameter: function ( singleParam ) { return statements } //Function with one and more parameter: function (param1, param2, …, paramN) { return statements } //Function with simple return statement: function (n