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 :
Example :
Calculate the total price of the product, and return the result
TUTORIAL
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 :
In Function Return Statement, the function will stop further execution code and return the main execution code.function function_Name(Parameter1, Parameter2, Parameter3) {// code to be executed}
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>
How to call a function inside a function in javascript?
ReplyDeleteHow to add multiple functions in javascript?
ReplyDeletePlease add one more post about the,
ReplyDeleteHow many types of functions in JavaScript?