Hacker News new | ask | show | jobs
by true_religion 1709 days ago
I agree. You should type something as null if you need to force callers to deal with the null value and can't do that with an exception.

Type it as void if the value isn't really important to the caller, or you'll throw exceptions in an exceptional case.

Common wisdom is to always have user-defined functions return void, but sometimes I think it's okay to use void if you're replacing a built in JavaScript functionality so the outer code was relying on that semantic. For example, replacing a simple usage of findIndex (that returned undefined) with something more complex that does API calls.