Functions in JavaScript and It's Example

Functions in javaScript:

A JavaScript function contains some code that will be executed only by a event or by a call to that function.

The function can be called from anywhere within the page or from other external pages.

Functions can be defined either<head> or <body> tag.

The most common way to define a function (optional), and a statement block surrounded by curly braces.

As a convention, they are typically defined in the <head> </head> section.


Syntax:




Calling a Function:

The syntax to invoke a function is:



Example:

Result: