HTML and CSS Reference
In-Depth Information
the placeholder for
the Data to be passed
into the function,
called the parameter
goes in parentheses.
A label gives
the function a
name.
The function keyword
indicates a function
declaration.
function dblMe(n) {
return 2 * n;
}
The return keyword
ends the function
and sends a value
back.
the code to be executed (the
function body) is placed
between braces.
This function is short enough that
you can experiment with it in the
console. To run the code in the
function (or call the function, as a
developer would say), you use the
function name followed by paren-
theses containing the argument
you want to pass. The argument is
assigned to the parameter within
the function body.
It's worth explaining that again: the parameter is the placeholder in the
function definition. The argument is the value passed into the function
when it's called. In practice, people ignore this subtle distinction and
use the two terms interchangeably; we'll try to keep them straight, but
don't worry about the difference too much.
Real functions generally contain more complex logic, but the examples
here are short so it's feasible for you to type them into the console.
Here's a slightly more complex example.
Search WWH ::




Custom Search