Answer: Use the syntax
function keyword, followed by the name of the function, a pair of parentheses (opening and closing), and a code block.
Let's take a look at the following example to understand how to define a function in JS.
ExampleTry this code »
Here are some more FAQ related to this topic:
- How to define a function in jQuery
- How to call a function after waiting for some time in jQuery
- How to call a function repeatedly after fixed time interval in jQuery