function defaultFunc(x = 1, y = 2, z = 3) {
console.log(x, y, z);
}
defaultFunc(5);
defaultFunc(5, 6);
defaultFunc(undefined, 6, 7);
function getData(data, useCache = true) {
if (useCache) {
console.log('using cache for', data);
}
else {
console.log('not using cache', data);
}
}
getData('abc');
getData('def', false);
Output
5 2 3
5 6 3
1 6 7
using cache for abc
not using cache def