JSFiddle - React, Tailwind, and code Playground
JavaScript
function objExample1( x ) {
console.log(x.length);
}
function objExample2( x = [] ) {
console.log(x.length);
}
//objExample1();
// Cannot read property 'length' of undefined
objExample1(['test']);
// 1
objExample2();
// 0
objExample2(['test']);
// 1
const $initSetup = {
width: 400,
height: 200,
background: 'blue'
}
function defaultTest({
width = $initSetup.width,
height = $initSetup.height,
background = $initSetup.background
} = $initSetup) {
console.log(`'${width} x ${height}' with background: ${background}.`);
};
let $userSetup = {
width: 250,
background: 'red'
}
defaultTest();
//'400 x 200' with background: blue.
defaultTest($userSetup);
//'250 x 200' with background: red.