Synchronous JavaScript
As the name suggests synchronous means to be in a sequence, i.e. every statement of the code gets executed one by one. So, basically a statement has to wait for the earlier statement to get executed.
Example: In this example, we have shown the synchronous nature of JavaScript.
javascript
document.write( "Hi" ); // First document.write( "<br>" ); document.write( "Mayukh" ); // Second document.write( "<br>" ); document.write( "How are you" ); // Third |
Output:
In the above code snippet, the first line of the code Hi
will be logged first then the second line Mayukh
will be logged and then after its completion, the third line will be logged How are you
. So as we can see the codes work in a sequence. Every line of code waits for its previous one to get executed first and then it gets executed.