by @kodeazy
How to create a global function in JavaScript?
In this blog we will discuss on how to create a global function in javascript.
Below is an example of creating a normal function
in javascript
globalFuncExample(){
// coding part..
}
To create a global function we use window
keyword.
Below is the syntax of creating a gloabl function
for above normal function
in javascript.
window.globalFuncExample=function(){
// coding part...
}
Below is an example of creating a global function in javascript.
<html>
<head>
<script>
window.globalFuncExample=function(){
alert("Global function clicked");
}
</script>
</head>
<body>
<div id="globalFuncExample" onclick="globalFuncExample()">click me</div>
</body>
</html>