Es6 Default Values

es6

// ES6 - Default values:

This is a thing that other language have had for a long time, and it is nice 
that JavaScript is catching up.

function getInfo(print=false) {
  if (print) {
    console.log(this.name, this.age);
  } else {
    return `${this.name} ${this.age}`;
  }
}

getInfo();

In the above code, if the parameter print is not specified, it is automatically 
default to false so that we do not have to worry inside if it is not defined.
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License