MOCKSTACKS
EN
Questions And Answers

More Tutorials









NodeJS v6 New Features and Improvement

Default Function Parameters


function addTwo(a, b = 2) {
 return a + b;
}
addTwo(3) // Returns the result 5

With the addition of default function parameters you can now make arguments optional and have them default to a value of your choice.

Rest Parameters


function argumentLength(...args) {
 return args.length;
}
argumentLength(5) // returns 1
argumentLength(5, 3) //returns 2
argumentLength(5, 3, 6) //returns 3

By prefacing the last argument of your function with ... all arguments passed to the function are read as an array.

In this example we get pass in multiple arguments and get the length of the array created from those arguments.

Arrow Functions


Arrow function is the new way of defining a function in ECMAScript 6.

// traditional way of declaring and defining function
var sum = function(a,b)
{
 return a+b;
}
// Arrow Function
let sum = (a, b)=> a+b;
//Function defination using multiple lines
let checkIfEven = (a) => {
 if( a % 2 == 0 )
 return true;
 else
 return false;
}


Conclusion

In this page (written and validated by ) you learned about NodeJS v6 New Features and Improvement . What's Next? If you are interested in completing NodeJS tutorial, your next topic will be learning about: NodeJS Eventloop.



Incorrect info or code snippet? We take very seriously the accuracy of the information provided on our website. We also make sure to test all snippets and examples provided for each section. If you find any incorrect information, please send us an email about the issue: mockstacks@gmail.com.


Share On:


Mockstacks was launched to help beginners learn programming languages; the site is optimized with no Ads as, Ads might slow down the performance. We also don't track any personal information; we also don't collect any kind of data unless the user provided us a corrected information. Almost all examples have been tested. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. By using Mockstacks.com, you agree to have read and accepted our terms of use, cookies and privacy policy.