Tutorial by Examples

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.
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 examp...
function myFunction(x, y, z) { } var args = [0, 1, 2]; myFunction(...args); The spread syntax allows an expression to be expanded in places where multiple arguments (for function calls) or multiple elements (for array literals) or multiple variables are expected. Just like the rest parameters s...
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) => { ...
this in function refers to instance object used to call that function but this in arrow function is equal to this of function in which arrow function is defined. Let's understand using diagram Understanding using examples. var normalFn = function(){ console.log(this) // refers to global/windo...

Page 1 of 1