All of us know that a function is a collection of statements executed when it is called at some point in a program. A function performs a specific task within a program independent of the other code in the program. We can call the function from anywhere within a program. We can also define the parameters to be passed to the function when the function is called. The parameters in a function are used to exchange information between a calling statement and the function. We can define a function by using the function keyword.Syntax for a functionThe above syntax has the name of the function and the parameters of the function.JavaScript functions are divided into two categories:Function without ParametersDoes not contain parameters. The code in these functions are static, implying that the values of the members of these functions cannot be changed at runtime.Function with parametersContains parameters in the parenthesis, such as integer and string. Unlike functions without parameters, the values of members of these function can be changed at run time by passing different values of their parameters.Now let's understand JavaScript functions using a simple example:We have created a function named simple under the head section.The simple() function shows an alert message with "Thank you". The onload event handler under the BODY element calls the simple() function when the document is loaded in the browser.Output :
You need to be a premium member to use this feature. To access it, you'll have to upgrade your membership.
Become a sharper developer and jumpstart your career.
$0
$
. 00
monthly
For Basic members:
$20
For Premium members:
$45
For Elite members: