Passing Data Inside

We can pass data into a function via parameters.

function showMessage(from, text = "no text added") {
  alert(from + ": " + text);
}

showMessage('Anna', 'Hello!'); // Anna: Hello!
showMessage('Anna'); // Anna: no text added

Parameters vs Arguments

  • Parameters are variables listed in the parentheses during the function declaration (from, text).
  • Arguments are the actual values passed to the function during the call ('Anna', 'Hello!').
Tip

In modern JS (since ES6), default values can even be the results of calling other functions!