2 ms·
Regarding throw and NaN, when the program throws an error, make sure it's restarted! When JavaScript throws, it stops doing whatever it was doing. But the rest
by z3t4 10y ago
Regarding throw and NaN, when the program throws an error, make sure it's restarted! When JavaScript throws, it stops doing whatever it was doing. But the rest of the program will continue to run like if nothing happened. NodeJS does the right thing by "crashing" / exit.
When you asume something in JavaScript, for example that the second parameter in the function is a callback function make sure it is!
if(typeof callback != "function") throw new Error("Expected callback=" + callback + " to be a callback function!");
if(isNaN(someNumber)) throw new Error("someNumber=" + someNumber + " is NaN! someState=" + someState);
if(something == undefined) throw new Error("something=" + something + " is undefined!");