How to call a function in JavaScript?

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.


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

         function sayHello() {
            document.write ("Hello there!");

      <p>Click the following button to call the function</p>
         <input type = "button" onclick = "sayHello()" value = "Say Hello">
      <p>Use different text in write method and then try...</p>

Updated on: 19-Jun-2020


Kickstart Your Career

Get certified by completing the course

Get Started