I’ve seen this tag used after javascript functions for over a decade now and never asked WHY. It’s seen in most of the tutorials I’ve seen over this time, but I usually leave it out… it doesn’t seem to have an effect one way or another. Can anyone enlighten me as to why this is used?
If it’s just to signify the end of a javascript function, wouldn’t the right brace be adequate? If it’s for a series of functions, the ending script tag is used.
I doubt I need an example, but for all the other readers out there that are also wondering what it’s for, here’s some code:
function helloWorld() {
document.write('Hello World');
}
//-->
Thanks in advance!
Back in the days, some browsers did not handle javascript so to avoid errors, you’d put the javascript code inside an HTML comment block “”.
Today, the XHTML standards says you should escape your script like
You don’t have to do that for HTML. Refer to: