Valentin Silvestre Posted on Apr 16, 2018 Explain Return Like I'm Five #explainlikeimfive Top comments (1) Subscribe Personal Trusted User Create template Templates let you quickly answer FAQs or store snippets for re-use. Submit Preview Dismiss Collapse Expand J Silverstein J Silverstein J Silverstein Follow React/Node developer Location NYC Work Full Stack UI Developer at J.Crew Joined Mar 11, 2017 • Apr 17 '18 • Edited on Apr 17 • Edited Dropdown menu Copy link Hide So, we can think of a function as a box that does things, right? We put things into the box and the box acts upon them. For example, imagine a box called "plus". The plus box will add together whatever things we happen to put into it. Like this: ┏━━━━━━━━━━┓ 1 ────> │ ───┐ ┃ ┃ 1 + 2 ┃ 2 ────> │ ─────────┘ ┃ ┗━━━━━━━━━━┛ Right now, we've used "plus" to add 1 and 2. We have 3, but it's just sitting in our box. We want 3 to be able to get out of the box: ┏━━━━━━━━━━┓ 1 ────> │ ───┐ ┃ ┃ 1 + 2 ────> 3 2 ────> │ ─────────┘ ┃ ┗━━━━━━━━━━┛ The return keyword is what allows us to get the 3 out of the box. Now, we give our box 1 and 2, and get 3 in return. Code of Conduct • Report abuse Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink. Hide child comments as well Confirm For further actions, you may consider blocking this person and/or reporting abuse
Top comments (1)
So, we can think of a function as a box that does things, right? We put things into the box and the box acts upon them.
For example, imagine a box called "plus". The plus box will add together whatever things we happen to put into it. Like this:
Right now, we've used "plus" to add 1 and 2. We have 3, but it's just sitting in our box. We want 3 to be able to get out of the box:
The
return
keyword is what allows us to get the 3 out of the box. Now, we give our box 1 and 2, and get 3 in return.