Do I need to add a backslash when closing tags using document.write? It seems to work with or without. Which one is correct? document.write("<h1>Hello world</h1>This is my website<br />Goodbye"); or document.write("<h1>Hello world<\/h1>This is my website<br \/>Goodbye"); Code (markup):
You do not need the backslash to escape the normal slash as it is not a special character You only need it to escape the usual meaning of a character e.g. if you would like to print a " you would nee the escape it with a backslash and write \" to print it