Jump to content

Script in the <head> container


cve60069
 Share

Recommended Posts

  • 2 weeks later...

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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...