Do I have to return something?

In javascript methods, I usually don't return anything if I don't need to. But then the question arose. How does javascript clear memory if I don't return anything? I know that JS uses the garbage collector .. so ... somehow it clears the memory for me. So my actual question is, what is considered to be BEST practice to return true or false even in situations where you are not expecting 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? } 
+4
source share
2 answers

Is the practice considered BEST true or false even in situations where you do not expect any return values, such as:

No.

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

Returning the value directly affects garbage collection. I'm not sure why you think it could be.

+9
source

Even if you don’t return anything, the javascript runtime knows that the function is complete, and now it can clear after it. Returning some dummy value will not help here.

+6
source

Source: https://habr.com/ru/post/1388204/


All Articles