I have seen in many times in JavaScript code people add a return true at the end although not necessary. Does anyone know why?
var _globalString;
function doSomething()
{
_globalString= _globalString +' do something';
//some codes to do something more
//finally adding a return true
return true;
}
The thing that may have gotten some people into the habit was event handlers for forms, if you have, say:
and
myfunction()returns true, the form submits, else if it returns false it doesn’t. People doing it in general could’ve got the habit from this. Some languages require return values from functions, Javascript doesn’t; and havingreturn trueat the end of most functions serves no purpose.