FUNCTIONS

For what?

The concept

  • Function Definition
  • Function Call(s)

FUNCTION DEFINITION

function decorateMyName() {
    console.log("************");
    console.log("John Doe");
    console.log("************");
}

FUNCTION CALL

decorateMyName();

A PARAMETER

It's the input!

PARAMETER EXAMPLE

(DEFINITION AND CALL)

function decorate(name) {
    console.log("*******************");
    console.log(name);
    console.log("*******************");
}

decorate("John");
decorate("Marie");

RETURN VALUE

It's the output!

RETURN VALUE EXAMPLE

(DEFINITION AND CALL)

function getGreeting(name) {
    return "Hello " + name + "!";
}

// call a function with a parameter and
// save the return value to a variable  
var greeting = getGreeting("Matt");
// you can use the variable value now wherever you want
console.log(greeting);