Friday, December 15, 2017

[JavaScript][Exercise] Throw Error if without argument.

Implement the ensure function so that it throws an error if called without arguments or the argument is undefined. Otherwise it should return the given value.

Reference answer

function ensure(value) {
  if(value === undefined) throw new Error('no arguments');
  return value;
}

Reference 

https://stackoverflow.com/questions/44874410/javascript-function-should-throw-an-error-if-called-without-arguments-or-an-argu

No comments :

Post a Comment