This is a very frequent pattern.
You can test it using
function parameterTest(bool) {
if (bool !== undefined) {
You can then call your function with one of those forms :
parameterTest();
parameterTest(someValue);
Be careful not to make the frequent error of testing
if (!bool) {
Because you wouldn't be able to differentiate an unprovided value from false
, 0
or ""
.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…