JavaScript Functions


A function in JavaScript is a block of code designed to accomplish a particular task. You create it once, and you can execute (or "invoke") it whenever you need to perform that task in your program.

A JavaScript function executes when it is invoked by a section of your code.

Syntax

function function_name (parameter1, parameter2 ... parameter-n) {
   // body
}