InterviewSolution
Saved Bookmarks
| 1. |
Explain Prototype chain in JavaScript using Object.create()? |
|
Answer» The setTimeout() function is used in JavaScript to delay a function call. For example, if you want to delay the function call by 5 seconds, then you can easily achieve this using the setTimeout() function. The following is the syntax: setTimeout(func_name, milliseconds, arg1, ARG2, ...)Here,
The following is an example: Let’s say we want the function cal to delay by 3 seconds, therefore we will implement the setTimeout( with a parameter as 3000 milliseconds (i.e. 3 seconds): function display() { setTimeout(function(){ document.write("Displaying after 3 seconds..."); }, 3000); }The example: <!DOCTYPE html> <html> <BODY> <button onclick="display()">Click</button> <SCRIPT> function display() { setTimeout(function(){ document.write("Displaying after 3 seconds..."); }, 3000); } </script> <p>Wait for 3 seconds after clicking the button</p> </body> </html>The output displays a button: After 3 seconds, the following would be visible since we delayed the execution: |
|