Curriculum
Course: JavaScript Basic
Login

Curriculum

JavaScript Basic

JSHome

0/216
Text lesson

Function Definitions

JavaScript functions are defined using the function keyword.

You can define a function either as a function declaration or as a function expression.

Function Declarations

Earlier in this tutorial, you learned that functions are declared using the following syntax:

function functionName(parameters) {
  // code to be executed
}

Declared functions are not executed right away. Instead, they are “stored for future use” and are executed later when they are invoked (called).

Example

function myFunction(a, b) {
  return a * b;
}
Semicolons are used to separate executable JavaScript statements.
Since a function declaration is not an executable statement, it is not typical to end it with a semicolon.