# Function with return; etc

**URL:** <https://forum.freecodecamp.org/t/function-with-return-etc/376834>\
**Category:** General\
**Created:** [April 21, 2020, 4:53pm UTC](https://forum.freecodecamp.org/t/function-with-return-etc/376834 "2020-04-21T16:53:13Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![design](https://avatars.discourse-cdn.com/v4/letter/d/b5a626/32.png) [@design](https://forum.freecodecamp.org/u/design)\
**Post date:** [April 21, 2020, 4:53pm UTC](https://forum.freecodecamp.org/t/function-with-return-etc/376834/1 "2020-04-21T16:53:14Z")

</div>

```auto
function stepChk(f) {
	var all_ok = true;
	if (f.username.value.length < 2) { all_ok = false; }
	var msg = 'Your username must be 2 to 12 letters long !';
	if (!all_ok) { alert(msg); }
	return all_ok;
}

```

Can somebody explain what this function do exactly?

What if there is no return? Or just return;

Thanks!

---

<div class="post-metadata">

**Author:** ![bbsmooth](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/bbsmooth/32/203556_2.png) [@bbsmooth](https://forum.freecodecamp.org/u/bbsmooth)\
**Post date:** [April 21, 2020, 8:04pm UTC](https://forum.freecodecamp.org/t/function-with-return-etc/376834/2 "2020-04-21T20:04:49Z")

</div>

This is not that complicated of a function. What do you think it does?

If a function doesn’t explicitly return a value then it automatically returns `undefined`.

---

<div class="post-metadata">

**Author:** ![dareedyone](https://avatars.discourse-cdn.com/v4/letter/d/57b2e6/32.png) [@dareedyone](https://forum.freecodecamp.org/u/dareedyone)\
**Post date:** [April 21, 2020, 8:19pm UTC](https://forum.freecodecamp.org/t/function-with-return-etc/376834/3 "2020-04-21T20:19:12Z")

</div>

The function is a parametized function that is expecting an object which then check if the length value of the username property of the object is lesser than 2 then reset all\_ok variable to false. Then set the variable message and recheck for the not value of all\_ok to alert the message variable. In a simple sentence this function was supposed to make sure the length of username is greater than 2. It return all\_ok because i believe this function will be assign to a variable e.g

```auto
var all_ok = stepChk(obj);

```

which means the progammer has the need for the variable somewhere in the program. It is not compulsory you make a function return something.

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [June 1, 2021, 6:58pm UTC](https://forum.freecodecamp.org/t/function-with-return-etc/376834/4 "2021-06-01T18:58:05Z")

</div>

Closed on June 1, 2021, 6:58pm UTC


