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

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -