cve60069 Posted July 22, 2012 Share Posted July 22, 2012 Hello I am trying to understand the difference between using a <script> in the <head> of the document and the <body>: say to declare an array and its contents. Is there any information on the subject, please? Regards Link to comment Share on other sites More sharing options...
eTianbun Posted July 22, 2012 Share Posted July 22, 2012 Well, no difference, just that the <script> tag "content" in the <head> tag is executed 1st, before the one in the <body> tag. Link to comment Share on other sites More sharing options...
cve60069 Posted July 22, 2012 Author Share Posted July 22, 2012 In a W3S example - which I cannot find - created an array in the head. In no other example have I seen the author write a script in the head. Seemed inconsistent. Cheers Link to comment Share on other sites More sharing options...
cve60069 Posted July 22, 2012 Author Share Posted July 22, 2012 Codename Thanks for the link to the W3 site. Link to comment Share on other sites More sharing options...
cve60069 Posted August 2, 2012 Author Share Posted August 2, 2012 The difference between declaring variables in the <head> as opposed to the <body> statement is the value assigned to the variable is undefined in the head but is assigned in the body. put s1 = 2 in the head any alert(s1) gives undefined; put the expression in the body and alert returns 2. Link to comment Share on other sites More sharing options...
Ingolme Posted August 2, 2012 Share Posted August 2, 2012 That is not true. If you set the variable it will not be undefined regardless of where it was set. There is technically no difference between putting it in the head or the body. It's a good practise to keep everything out of the body except for the content structure. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now