Show Output
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>JavaScript Execute a Function after Some Time</title> </head> <body> <script> function myFunction() { alert('Hello World!'); } </script> <button onclick="setTimeout(myFunction, 2000)">Click Me</button> <p><strong>Note:</strong> Alert popup will be displayed 2 seconds after clicking the button.</p> </body> </html>