Es6 Default Values
// 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.
page revision: 0, last edited: 19 Feb 2017 07:04