Page 206 - Web_Application_v2.0_C12_Fb
P. 206

return value;  // Optional
                  }

                  functionName (argument1, argument2, ...);    //invoking the function
              For example:

                  function greet() {
                                                                    Notes
                  document.write("Hello, World!");
                                                                    Number of parameters (also called arguments)
                  }
                                                                    is not fixed. You may have no parameters or as
                  greet();                                          many as your function requires.
              Output:
              Hello, World!

              Named Function

              A function with a specific name that can be called anywhere in the code after its declaration.
              The syntax to create named function is as follows:

                  function functionName() {
                  // code block
                  }

                  functionName();
              Example 15: To demonstrate the use of named function

                  <!DOCTYPE HTML>
                  <HTML>
                  <HEAD>

                  <TITLE>Named Function in JavaScript</TITLE>
                  </HEAD>
                  <BODY>
                  <SCRIPT>
                  function displayMessage() {
                  document.write("This is a Named Function Example!");
                  }
                  displayMessage();
                  </SCRIPT>

                  </BODY>
                  </HTML>
              Output:
















                204   Touchpad Web Applications (Ver. 2.0)-XII
   201   202   203   204   205   206   207   208   209   210   211