Jump to content

help understanding code


afcbob
 Share

Recommended Posts

I have done HTML/CSS on here moving on to javascripting now but got to this one here and don't understand why there is some parts of the code.the 1st document.write(name) is in () with no " in it then the next one is and why does the next one have + in it.Hope you understand me. Thanks

Link to comment
Share on other sites

the 1st document.write(name) is in () with no " in it then the next one is
Using " " just means print whats inside to screen.
var name = "Hege"document.write(name)document.write("<h1>"+name+"</h1>")

document.write(name) - what is name? name is a variable with the value "Hege", so Hege will be printed to screen.If, for example, you said document.write("name") then name would be printed to screen, not Hege - so use of quotations is important.

why does the next one have + in it.
+ is used to add variables and strings togetherdocument.write("<h1>"+name+"</h1>")This would displayHege
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...