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

Popular posts from this blog

testing - Detect whether test has failed within fixture -

AbotX : How do you create a parallel crawler that stays on and can be added to at run time from new requests -

android - Create single AAR file from multiple modules using Gradle -