codeGK
Code it ALL
JavaScript Function - CodeGK
♦ JavaScript Function

♣ About JavaScript Function

A JavaScript Function is a block of code written to perform certain task.
A JavaScript Function can give different kind of output depending upon the arguments it accepts.
A JavaScript Function can be invoked over and over again, i.e, this is one of cool features of function declaration.

♣ JavaScript Function Syntax

Below is the representation of JavaScript Function Syntax.
Basic Syntax
function name_of_function(parameter1, parameter2, ...) { //can accept any number of parameters // code to be executed return value_return; //value that is to be returned }
Syntax Explanation:
name_of_function: name of the function parameter1, parameter2, ...: parameters for function value_return: return value, which will be returned upon completion of execution of function

♣ Example1: Function Call in JavaScript

Below shown is a simple function call, the function accepting two parameters and returning a number.
In this example, Simple Function Call is illustrated.
Example
Input:
Output:

♣ Example2: Nested Function in JavaScript

Below is the illustration of function call from inside of other function.
In this example, Nested Function Call is illustrated.
Example
Input:
Output:
Prev_LessonNext_Lesson