📜  javascript 函数所需的参数 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:03:57.409000             🧑  作者: Mango

代码示例1
const isRequired = () => { throw new Error('param is required'); };

const hello = (name = isRequired()) => { console.log(`hello ${name}`) };

// This will throw an error because no name is provided
hello();

// This will also throw an error
hello(undefined);

// These are good!
hello(null);
hello('David');