In short, a function is the sum or block of a number of statements. Which can be created once and called briefly and used repeatedly in different parts of the program as needed. This reduces the amount of coding in the program. Moreover, the built-in functions of various programs can be used by a programmer only directly in Kolkata, making programming much easier. We can easily become skilled programmers in a short period of time by knowing the effectiveness and usage of all these built-in functions. It also reveals the special features of a skilled programmer on creating the necessary user defined functions in the program and its proper application.
Create function
The function keyword is used first to create the function. Then the name of the function is written (the name by which the function is called later) followed by a fast bracket. And if the function has one or more arguments or parameters, it has to be specified in fast brackets. Then in the second bracket the main part of the function (where the necessary statements are required to perform the task) is written. That is, the syntax of a function
FunctionName (Argument1, Argument2)
{
Statement1
Statement2
.
}
The function has to be created first and then called. So in JavaScript, functions are usually created in the <head> </head> section of the web page, or in an external JavaScript file.
Practice project
<html>
<head>
<title> www.tutohost.com </title>
<style>
body {background: #FFC;
font-size: 20px;
h2 {color: # FF0066;
</style>
<script type = "text / javascript">
function AboutTutohost ()
{
document.write ("<h2> About Tutohost </h2>");
document.write ("<p> We are relaibale Bangladeshi hosting provider. The world wide technical and support team is working for your best movement. We are dedicated with client requrement.You can host your huge data of your company with our secured and hacking proof server. We are taking care of more than 1000 bangladeshi websites and their huge information. </p> ");
}
</script>
</head>
<body>
<script type = "text / javascript">
aboutTutohost ();
</script>
</body>
</html>Open a notepad, type the code above and click Save as from the file menu. File name: index.html, Save as type: All files, and save the index.html file with Mozilla Firefox.
Program analysis
<Script type = "text / javascript"> </script> has been added to the program above to include JavaScript code in the <head> </head> section.
The function keyword was first used to create the function using function AboutTutohost () and the function was named as AboutTutohost.
মূল The main statements of the function are written in 6 second brackets. Here are two document.write (); Through this a heading and a paragraph have been created.
Later in the <body> </body> section <script type = "text / javascript"> AboutTutohost (); </script> was added. Here AboutTutohost (); This calls the declared function in the <head> </head> section.
This function is a simple general function with no arguments. And the AboutTutohost () function returns no value.