ES6 in Depth
  • Introduction
  • Installation
  • Block Scope
    • Constant
    • Use cases
  • Template String
    • New String Methods
    • Tagged Template Literal
  • New Number Methods
  • Arrow Function
    • Default Parameters
    • Lexical This Scope
    • Where not to use arrow function
  • Object Enhancement
  • New Array Methods
    • For Of
  • Spread Operator
  • Destructuring
    • Array Destructuring
  • Class
  • Symbols
  • New Data Structures
    • Set
    • Map
    • WeakSet
    • WeakMap
    • Iterators
    • Generators
  • Promise
  • Import Export
Powered by GitBook
On this page

Was this helpful?

  1. Arrow Function

Default Parameters

function greet(greeting, name="Anonymous"){
    console.log(greeting +", "+ name);
}

greet(); // undefined, Anonymous
greet('Hello'); // Hello, Anonymous
greet('Hello', 'Dady'); // Hello, Dady
// ES5
function greet(cb){
    cb();
}

greet(function(){
    console.log("completed"); // completed
})

// ES6
function greet(() => console.log("completed")){
    cb();
}
greet();
PreviousArrow FunctionNextLexical This Scope

Last updated 4 years ago

Was this helpful?