JavaScript

How to define a function in JavaScript?

The following example will show you how to define a function in JavaScript. In the following code, when the button is clicked, the function we defined in line 10 will be called.
 

How to define a function in JavaScript?
<!DOCTYPE html>
<html>
  <head>
    <title>Define a function in JavaScript</title>
  </head>
  <body>
    <script>
      function myFunction(){ 
        alert("You have successfully defined a function!"); 
      }
    </script> 
    <button type="button" onclick="myFunction();">Click Here!</button>
  </body>
</html>
Result
Define a function in JavaScript
mcqMCQPractice competitive and technical Multiple Choice Questions and Answers (MCQs) with simple and logical explanations to prepare for tests and interviews.Read More

Leave a Reply

Your email address will not be published. Required fields are marked *