How to call a function in JavaScript?

JavascriptWeb DevelopmentFront End Technology

JavaScript allows us to write our own functions as well. To invoke a function somewhere later in the script, you would simply need to write the name of that function.

Example

You can try to run the following code to learn how to call a function in JavaScript −

<html>
   <head>
      <script>
         function sayHello() {
            document.write ("Hello there!");
         }
      </script>
   </head>

   <body>
      <p>Click the following button to call the function</p>
      <form>
         <input type = "button" onclick = "sayHello()" value = "Say Hello">
      </form>
      <p>Use different text in write method and then try...</p>
   </body>
</html>
raja
Published on 16-Feb-2018 15:44:00
Advertisements