Jump to content

JavaScript: Difference between revisions

no edit summary
No edit summary
Line 1: Line 1:
JavaScript is a single-threaded programming language. In the browser, JS is event-driven, meaning that after initialization, the JS engine is idle until an event occurs such as a button being pressed in the DOM.
This page is a mostly about browser-based JavaScript or ECMAScript usage and interaction with the HTML DOM (window).
This page is a mostly about browser-based JavaScript or ECMAScript usage and interaction with the HTML DOM (window).
For server and desktop application JavaScript usage, please see the [[NodeJS]] page.
For server and desktop application JavaScript usage, please see the [[NodeJS]] page.
Line 270: Line 272:
}
}
</syntaxhighlight>
</syntaxhighlight>
==Web Workers==
By default, JavaScript is a single-threaded language. For things that take a long time, people usually use asynchronous JS through promises and callbacks. However, if you have a heavy calculation that needs to be performed, you can use spawn web workers which will run in background threads. NodeJS also has a similar concept called [https://nodejs.org/api/worker_threads.html Worker Threads].
===Getting Started===
;Your main JS file:
;Your worker JS file:
Resources
* [https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Using_web_workers MDN: Using web workers]
* [https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API Web Workers API]


==Useful Packages==
==Useful Packages==