JavaScript Functions

A JavaScript function is a block of code to perform a specific task.

JavaScript Function Syntax

A JavaScript function is defined with the function keyword, followed by a name, followed by parentheses ().


Function names can contain letters, digits and underscores.

A User-defined function name should be unique.

The parentheses may include parameter names separated by commas:
(parameter1, parameter2, ...)

The code to be executed by the function, code is placed inside curly brackets: {}

Syntax :

function function_Name(Parameter1, Parameter2, Parameter3) {
  // code to be executed
}
In Function Return Statement, the function will stop further execution code and return the main execution code.

Example : 

Calculate the total price of the product, and return the result

var result = cal(10, 20); // Function is called, number of product and price of product pass as parameters function cal(a, b) { return a * b; // Function returns the product of a and b Multiplied value }

TUTORIAL

<html> <body> <p id="result"></p> <script> var result = cal(10, 20); // Function is called, number of product and price of product pass as parameters function cal(a, b) { return a * b; // Function returns the product of a and b Multiplied value } document.getElementById("result").innerHTML = result; </script> </body> </html>

3 comments:

  1. How to call a function inside a function in javascript?

    ReplyDelete
  2. How to add multiple functions in javascript?

    ReplyDelete
  3. Please add one more post about the,

    How many types of functions in JavaScript?

    ReplyDelete