Call function JavaScript
1.
A JavaScript function is a block of reusable code, that we can execute many times.
A JavaScript function is executed when "something" invokes it (calls it).
A JavaScript function is defined with the function keyword, followed by a name, followed by parentheses ().
Function names can contain letters, digits, underscores, and dollar signs (same rules as variables).
The parentheses may include parameter names separated by commas like (parameter1, parameter2, ...)
The code to be executed, by the function, is placed inside {}
2.
function keyword is used to declare the function
function can be called when an event occurs, like when the user clicks a button.
Code:-
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<h1>Function</h1>
<!--onfocus,onchange,onmouseover,onmouseout,onkeydown,onload-->
<button type="button" onclick="call_fun();">Call Function</button>
<script>
function call_fun()
{
alert("Function Called");
}
</script>
</body>
</html>
Syntax write example
<script>
function myFunction() {
//Here you can write your javascript code
}
</script>
No comments: