Search⌘ K
AI Features

Default Parameters

Understand how to use ES6 default parameters to assign values in function definitions when no arguments are passed. Explore how default parameters improve flexibility and clarity by allowing optional values in JavaScript functions. Learn to write cleaner and more reliable code with these new ES6 features.

We'll cover the following...

Default Parameters are a great addition to the language. They allow you to, well, add default parameters. And this solves a very simple problem.

Javascript (babel-node)
function getData(url) {
url = url || 'http://api.data.com';
return fetch(url)
.then(res => res.json);
}

Consider the above, a simple function to get data from a ...