function test(variable, check) {
var check = check || ???;
if (variable == check) {
//do stuff
}
}
I want this function to check if the variable is anything that if(variable) return true;
would return true, any number greater than 0 for example. I'd like to keep this simple formatting and use the ==
operator for when check
is a specific value if possible, so what could I default it to in order to achieve this?
I could achieve the same thing with this code:
function test(variable, check) {
if(check) {
//check specific value
if (variable == check) {
//do stuff
}
} else {
//check isn't set, so accept any truthy values (like 5 or 'string')
if(variable) {
//do stuff
}
}
}