javascript - If function is called with null or undefined show error, else return value -
i'm trying make function return error or value. if argument null or undefined throw error. whats wrong ?:
function get(value){ if (value == null){ return false; } else { return value; } }
i don't understand requirement 100%, in order produce en error, can use "throw" keyword:
function get(val) { if (val == null) { throw 'value eithr null or undefined'; } return val; }
Comments
Post a Comment