What are different ways to use the JavaScript?

 JavaScript can be used using three ways

  • Immediate Script
    • Code get executed automatically when  we load a web page
  • Deferred Script
    • Code get executed based on some event
    • We need to create a function to link with some event attribute
    • Use function keyword to define the functions in the JavaScript
  •  Hybrid Script
    • Some code get executed at the time of loading the page and other code get executed based on some event
Example of Immediate Script

<script>
//immediate script code
alert("Welcome to JavaScript");
</script>

Example of Deferred Script

<script>
function welcome(){
alert("OOPs! You Clicked");
}
</script>

<input type="button" value="Click Me" onClick="welcome()">

Example of Hybrid Script

<script>
alert("This is an example of Hybrid Script");
function welcome(){
alert("OOPs! You Clicked");
}
</script>

<input type="button" value="Click Me" onClick="welcome()">

Comments

Post a Comment