In the following code document.write("<h1>" + Date() + "<\/h1>"); I need to use \ in the closing h1 tag to validate my HTML page. Whats the purpose of using \ in the tag.
In the following code document.write(<h1> + Date() + <\/h1>); I need to use \
Share
There is no formal error in your JavaScript code. The problem is probably that you have it inside an HTML document, in a
scriptelement, and then</h1>may become a problem (depending on HTML version and software used). At the HTML level, the\breaks the construct so that it won’t be parsed as an end tag. In a JavaScript literal,\/means just the same as/(you can “escape” a normal character, too).