JavaScript itself is synchronous and single-threaded. You cannot write an asynchronous function; plain JS has no timing API. There will be no side-effects from parallel threads.
What you can do is use some APIs provided by your environment (Node.js, Webbrowser) that allow you to schedule asynchronous tasks - using timeouts, ajax, FileAPI, requestAnimationFrame, nextTick, WebWorkers, DOM events, whatever.
An example using setTimeout (provided by the HTML Timing API):
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy.
<!DOCTYPE html> <html lang='en' xmlns='http://www.w3.org/1999/xhtml'> <head> <meta charset='utf-8' /> <title>Asynchronous JavaScript </title> <script> window.setTimeout(function () { console.log('Hello World'); }, 1000); document.write('Hello'); </script> </head> <body align='center'> <h1>Asynchronous JavaScript</h1> </body> </html>Hope this information has cleared your confusion.
Happy Coding!