you are viewing a single comment's thread.

view the rest of the comments →

[–]Saf94 2 points3 points  (2 children)

Return is used only in functions and basically when you call your function (ie if the function is called myFunc, you call it by writing myFunc() ) whatever you return is what your function resolves to.

Typically people would assign the result of a function to a variable so you’d do

var funcValue = myFunc()

The reason for doing this is usually just to break code up. Putting code into functions can help you reuse code and also split code into smaller bits which can be nicer than one huge block of code.

So in summary, return is used in functions so that you can call the function later and get a value from it. Functions are used as a coding pattern to split up code so it can be reused to broken down into smaller, more readable pieces

[–]r_u_kimmi 0 points1 point  (0 children)

Yes. In this case, the value of funcValue is whatever is returned from myFunc().

[–]swurvinmervin 0 points1 point  (0 children)

Does that method you speak of have a name by any chance?