JavaScript: Difference between revisions

Content deleted Content added
Wdanbae (talk | contribs)
mNo edit summary
Wdanbae (talk | contribs)
Line 160:
 
=== Miscellaneous ===
; Run-time environment: JavaScript typically relies on a run-time environment (e.g., a [[Web browser]]) to provide objects and methods by which scripts can interact with the environment (e.g., a webpage [[Document Object Model|DOM]]). It also relies on the run-time environment to provide the ability to include/import scripts (e.g., [[HTML]] <tt><nowiki><script></nowiki></tt> elements). This is not a language feature per se, but it is common in most JavaScript implementations.
 
: JavaScript processes [[Message (computer science)|messages]] from a [[Queue (abstract data type)|queue]] one at a time. Upon loading a new message, JavaScript calls a [[Subroutine|function]] associated with that message, which creates a [[call stack]] frame (the function's [[Parameter (computer programming)|arguments]] and [[local variable]]s). The call stack shrinks and grows based on the function's needs. Upon function completion, when the stack is empty, JavaScript proceeds to the next message in the queue. This is called the [[event loop]], described as "run to completion" because each message is fully processed before the next message is considered. However, the language's [[Concurrency (computer science)|concurrency model]] describes the event loop as [[Asynchronous I/O|non-blocking]]: program [[input/output]] is performed using [[Event (computing)|events]] and [[Callback (computer programming)|callback functions]]. This means, for instance, that JavaScript can process a mouse click while waiting for a database query to return information.<ref>{{cite web|title = Concurrency model and Event Loop|url = https://developer.mozilla.org/en-US/docs/Web/JavaScript/EventLoop|website = Mozilla Developer Network|accessdate = 2015-08-28}}</ref>