Javascript functions variables scope

All about Functions

Lesson 2 covers functions in Javascript. The basic idea of a function is to simplify input and reduce repetition. For example we can write:

var myAnswer = (prompt("Do you prefer Apples or Pears"));
if ( myAnswer === "Apples") {
    console.log("I eat Apples");
}
else {
    console.log("I eat Pears");
}

But if we use a function we can reduce the complexity by not having to repeat the command.

Subscribe to RSS - Javascript functions variables scope