TIL Default Params in Javascript
POSTED ON:
TAGS: javascript
ES6 version:
function say(message='Hi') {
console.log(message);
}
say(); // 'Hi'
say(undefined); // 'Hi'
say('Hello'); // 'Hello'
function createDiv(height = '100px', width = '100px', border = 'solid 1px red') {
let div = document.createElement('div');
div.style.height = height;
div.style.width = width;
div.style.border = border;
document.getElementsByTagName('body')[0].appendChild(div);
return div;
}
Related TILs
Tagged: javascript