Why isn't a good practice put void(0) when a function doesn't return anything explicitly?
function someFunc(a) {
// do some stuffs
return void(0);
}
This would help very much when debugging stuffs.
Thanks.
Why isn't a good practice put void(0) when a function doesn't return anything explicitly?
function someFunc(a) {
// do some stuffs
return void(0);
}
This would help very much when debugging stuffs.
Thanks.
Since void(0)
resolves to undefined
, the question could just as well be "why isn't it a good idea to return undefined
from a function?". Using void(0)
as an alternative to undefined
is probably a bad idea, relatively speaking, because it's more complex than undefined
, and less explicit. Our goal as programmers is to make simple, readable code for others to read and make sense of.
It's a bad idea to explicitly return undefined
from a function for the same reason, it introduces unnecessary complexity. typeof undefined
evaluates to undefined
. This makes writing tests more difficult and gives you less insight into the purpose of a function than does, say, returning false
.