Page 210 - Web_Application_v2.0_C12_Fb
P. 210

return (5/9) * (f-32);
                  }
                  result=Convert_to_Celsius(76.5);

                  document.write("The Celsius temperature is "+result);
                  </SCRIPT>
                  </BODY>
                  </HTML>
              Output:



















              Inner Functions

              JavaScript supports nested functions i.e., function defined inside another function. Only statements in the outer
              function can access the inner function. The inner function can make use of the arguments and variables of the
              outer function. However, the outer function cannot make use of the inner function’s arguments and variables.
              Example 20: To demonstrate how to inner function

                  <!DOCTYPE HTML>
                  <HTML>

                  <HEAD>
                  <TITLE>JavaScript Inner Function Example</TITLE>
                  </HEAD>
                  <BODY>

                  <H2>JavaScript Inner Function</H2>
                  <SCRIPT>
                  function add() {
                  var ctr = 10;

                  function inc() {ctr += 5;}
                  inc(); //call to inner function
                  return ctr;
                  }

                  document.write(add()); //call to outer function
                  </SCRIPT>
                  </BODY>
                  </HTML>

                208   Touchpad Web Applications (Ver. 2.0)-XII
   205   206   207   208   209   210   211   212   213   214   215