What use <! - and // & # 8594; in javascript?
Possible duplicate:
Why does this Javascript code inside the non-Javascript browser have an additional comment?
Sometimes I see Javascript that starts with <!-- and ends with //--> .
I wonder what is the use of such a line? As far as I know, <!-- means a comment line. But this does not seem to be the case, since the script will work even with such a string. And it also works if the row is deleted.
Here is one short example:
<script language='JavaScript' type='text/javascript'> <!-- function changelang(id) { document.location.href='index.php&lch=1&lang=' + id } //--> </script> Previously, it was used for older browsers that did not understand script tags and displayed their contents as text, which, of course, was undesirable.
This may make more sense if you think about the contents of the canvas , audio , noscript elements (the last of which is considered in a special way today, but imagine in the old days when the browser did not know that the noscript element was).
On this day and age is not required.
Douglas Crockford recommends against using them.
Do not use the script
<!-- //-->with scripts. It was designed to prevent scripts from appearing in the text of the first generation of the Netscape 1 and Mosaic browsers. This was not necessary for many years.<!-- //-->should signal HTML comment. Comments should be ignored, not compiled and executed. In addition, HTML comments do not include--, so a script that has a decrement has an HTML error.