Return Keyword


What exactly is this asking for us to do? I am horribly confused.

In our example, we have a function called timesTwo() that takes in a number and returns the number multiplied by two.

On line 7, after the equals sign, call the function timesTwo with any parameter you want
Line 8 prints out newNumber. Notice how the value we return from timesTwo() is automatically assigned into newNumber.

I'm following directinos with zero results


Here are two terms that won't come up in the course but that are useful in getting an understanding of functions.

  1. The expression making the call to a function is called, the caller.
  2. The function that has been invoked is called, the callee.
  3. The callee is a different environment from the caller.
  4. The callee can see variables in the caller scope.
  5. The caller cannot see variables in the callee scope.
  6. The caller may pass data to the callee by means of the parameter list.
  7. The callee takes the parameters as arguments to the function.
  8. The callee may have data to return to the caller.
  9. The return keyword is able to pass data back up the scope chain.

And there we have it.

    var foo = function (bar) {
        return "foo" + bar;
    var fooBar = foo("bar");
    console.log(fooBar);    // foobar  << this is the return value


You're the best. Thank you!



A post was split to a new topic: sleepCheck - need help


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.