In JavaScript all functions return, even if you don´t explicitly make them return. If there are no return statement a function will return undefined. There is however one exception to this. If you use the new statement the function will return an instance of this.
So:
function doFoo()
{
// do nothing
}
,
function doFoo()
{
return;
}
and
function doFoo()
{
return undefined;
}
are all the same to the JavaScript engine.
I really can´t recommend using null as return value in JavaScript. null is an object and doing type checking can lead to weird logic. If you use null as return you better change the expression in the if() to be more explicit.
foo = getReferenceToFoo('myID');
// foo might be a reference or null
if (null !== foo) {
// do things
}
EDIT: changed from the not equality operator (!=) to the strict not equality (!==).
But honestly I don´t know why you are doing this. The method document.getElementById returns null if it can´t find anything.
I know this is a antipattern but I actually do use:
var myElmnt;
if ((myElmnt = document.getElementById('myId')))
{
// do stuff with myElmnt
}
Yeah, I know, I will burn in hell and all.