Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I return something?

Tags:

javascript

In javascript methods, I usually don't return anything if I don't have to. But then a question poped up. How does javascript clears the memory if I don't return anything? I know that JS uses garbage collector..so..somehow it clears memory for me. So my actual question is, is it considered a BETTER practice to return true or false even in those situations you don't expect any return values such as the following?

// assuming we get birthday in mm/dd/year format
function setAge( birthDay )
{
    var _birthdaySplited = birthDay.split("/");
    this.age = new Date().getFullYear() - parseInt( _birthdaySplited[2] );

    // should I say..return true here?
}
like image 373
Moon Avatar asked Dec 06 '22 17:12

Moon


1 Answers

Is it considered a BETTER practice to return true or false even in those situations you don't expect any return values such as the following?

No.

How does javascript clears the memory if I don't return anything?

Not explicitly returning a value has effectively zero impact on garbage collection. I'm not sure why you think it might.

like image 91
Matt Ball Avatar answered Dec 21 '22 11:12

Matt Ball