Skip to content

Instantly share code, notes, and snippets.

@harryworld
Last active August 29, 2015 14:02
Show Gist options
  • Save harryworld/0d422bd97596dfaba89e to your computer and use it in GitHub Desktop.
Save harryworld/0d422bd97596dfaba89e to your computer and use it in GitHub Desktop.
FUNCTION vs RETURN vs SCOPE

Summary

Generally speaking, a function is a "subprogram" that can be called by code external (or internal in the case of recursion) to the function. Like the program itself, a function is composed of a sequence of statements called the function body. Values can be passed to a function, and the function can return a value.

4 essential parts of Function:

1. function name

The same as a variable name

2. -> arrow symbol

Divided into thin arrow (->) and bold arrow (=>)

3. arguments

Arguments will be brought into the function

4. return value

The last line of function always be returned

Scope

  • Outside Scope vs Inside scope
  • Function will create a new scope

There are several ways to make new scope:

  1. Function
  2. Loop
  3. if...then...else

Resources

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment