How many JavaScript programs are executed for a single web-page in the browser?

Dmitry Soshnikov has answered your question. Every script element is executed as a Program, as defined by the ECMAScript specification. There is one global object that each Program within a single page uses.

And that's really it.

Dmitry Soshnikov has answered your question. Every element is executed as a Program, as defined by the ECMAScript specification. There is one global object that each Program within a single page uses.

And that's really it.

Function hoisting — the process that evaluates function statements before the rest of the function — is part of the ECMAScript standard IIRC (I can't find a reference right now, but I recall seeing discussions of EMCAScript that mention it). The evaluation of script tags is part of the HTML standard. It does not specify that they are "separate programs" in so many words, but it does say that the script elements are evaluated in the order they appear in the document.

That is why functions in later script tags aren't hoisted: The script hasn't been evaluated yet. That also explains why one script stopping doesn't cut off subsequent scripts: When the current script stops evaluating, the next one starts.

Link explaning HOISTING. Adequatelygood.com/2010/2/JavaScript-Scoping-and-Hoisting – Rajat Oct 14 '10 at 21:02.

They are separate programs, but they modify a shared global object.

Another way to think about this is pseudo local vs global scope. Every SCRIPT declaration has a local scope to it's current methods/functions, as well as access to the current (previously declared) global scope. Whenever a method/function is defined in a SCRIPT block, it is then added to the global scope and becomes accessible by the SCRIPT blocks after it.

Also, here's a further reference from W3C on script declaration/handling/modification: The dynamic modification of a document may be modeled as follows: All SCRIPT elements are evaluated in order as the document is loaded. All script constructs within a given SCRIPT element that generate SGML CDATA are evaluated. Their combined generated text is inserted in the document in place of the SCRIPT element.

The generated CDATA is re-evaluated. This is another good resource on script/function evaluation/declaration.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions