DEV Community

Discussion on: Explain Empty Returns Like I'm Five

Collapse
 
theredspy15 profile image
Hunter Drum

Its commonly useful for when you need to end the function rather than return anything from the function.

In other words: functions don't always need to return a value to be useful, that can also perform tasks like printing a bunch of "Hello Worlds" to the screen. Whenever we return in a function, it stops executing that function (unless called again) at that exact line. It doesn't need a value to do this (technically it does, as blank is void & void is a value).

In short: the return statement isn't so much a "return" statement, as it is a statement that ends the function, and "returns" a value if there is one associated with it.

Collapse
 
chrisvasqm profile image
Christian Vasquez • Edited

Hey RedSpy,

Thanks for taking your time to comment. But the #explainlikeimfive hashtag is intended to be sort of like a "challenge" that involves explaining concepts with day to day situations so that an actual 5 year old can understand.

This may make things harder for those who reply but I've seen some really creative ideas here and there.

You can take these as example from Explain Dependency Injection Like I'm Five

Traditional: Picking what to wear when you get up in the morning.

Dependency Injection: Asking a pants, t-shirt and an hat from a stylist, and he makes sure you look lit AF.

"Dependency Injection" is a fancy way of saying that you have to ask someone else, like Mummy or Daddy, to give you anything you want to play with. You can't make the toy yourself, you need Mummy and Daddy to get it for you.

Sometimes, you don't know what toy you are going to get, like on your birthday, but all you need to know is that it will be a fun toy you can play with when you open the present.

Collapse
 
isaacdlyman profile image
Isaac Lyman • Edited

If I may add my two cents: all kinds of explanations are welcome on #explainlikeimfive. If we take the hashtag literally, we can't really get to the heart of a lot of technical topics. I mean, when I was five I was still potty training (sad, I know). I think simple--but perhaps not five-year-old simple--explanations are super valuable and this is a great place for them.

Thread Thread
 
chrisvasqm profile image
Christian Vasquez

Hey Isaac,

Yeah, you are right. I apologize if the way I expressed myself sounded like it was a mandatory way of doing it.

Collapse
 
theredspy15 profile image
Hunter Drum • Edited

Yah, I thought about that afterwards. If you would like me to remove the reply, I will

I did make sure it was simple enough that at least a 6 year old could understand (had to make this pun, sorry)

Thread Thread
 
chrisvasqm profile image
Christian Vasquez

Hahaha, don't worry 😂. Feel free to add the new one.