Is it always right to return to functions?

I read somewhere some time ago (unfortunately, I can’t remember where) that it would be wise to always put the operator returnat the end of each function in JavaScript, since it clears the memory of objects and variables created in this function.

Is there any truth to this?

+3
source share
2 answers

There is no truth to this. Are absent.

+7
source

No.

From the Standard Specification of ECMAScript ECMA-262 (12.9):

Syntax

ReturnStatement:
return ;
return[no LineTerminator here] Expression;

[...] return . Expression , undefined. .

, : return .

- MDN # :

function outside(x) {
   function inside(y) {
      return x + y;
   }
   return inside;
}
fn_inside = outside(3); 
result = fn_inside(5); // returns 8

result1 = outside(3)(5); // returns 8

, x inside. , . , outside . , inside .

+3

All Articles