How to print </ in javascript

I’m trying to print part of an xml tag in javascript, all I want is the </.

If I leave it like that I get the error that it’s an invalid regular expression.

If I add a backslash or two backslashes (</// or <//) I get an unexpected token error on both the first backslash.

Here is the code that I am working with:

function generateXMLLine(data, tag) {
    console.log("<" + tag + "> + data + "</" + tag + ">")
}

How do I do this in javascript?



String literals need to be surrounded with quote marks.

console.log("</");

Outside of a string; </ means “Less than” followed by the start of a regular expression literal (You need another / to end the regular expression: hence your error message).

You can use either innerText or innerHTML.