• Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.
    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

I need clarification in m understanding? Can someone help?

ayanda

New Coder
So a computer reads HTML (also CSS) and JavaScript from top to bottom and left to right, meaning it’s best to write code with that in mind?
 

Krusty the Senile

Active Coder
I think with all these that there are a number of passes over the source before the final output is considered.

CSS definitions will most likely be stored in memory and things that refer to them from the HTML will be read accordingly. In saying that, if there are multiple definitions for a style (eg. there's a CSS definition for an <a> tag in a CSS file, the HTML header, and for a specific tag) there will be an order of precedence that will be applied to the final <a> tag. I think with the control you get in positioning text of tags in a browser, you can't assume that the position of code within a HTML file corresponds to its position on the final page.

I was about to say that JavaScript takes multiple passes before deciding what to output, but I think not ... I don't think you can't call a JavaScript function or refer to a declaration before it's declared. eg:

JavaScript:
myFunc(); // this would fail, as myFunc() hasn't yet been declared

// sorry, it's been a while since I've done any JavaScript - this could be wrong
var myFunc = function() {
    // do something
}

This may depend on the execution environment (this I'm not sure about): a JavaScript file executed in a browser may behave differently to that executed in node.js for example.
 
Top Bottom