Passing Arguments in JavaScript

You can pass arguments into functions to be used within the function. These arguments can be any Javascript data type including functions.

var ifElse = function(condition, isTrue, isFalse, arg) {
  if (condition) {
    isTrue(arg); // this is called, passing in the myArg string
  } else {
    isFalse(arg);
  }
}

var funcOne = function(x) {
  console.log(x);
}

var funcTwo = function(x) {
  console.log(x);
}

ifElse(true, funcOne, funcTwo, 'myArg');