Quote:
|
Originally Posted by VWPhillips
/*<![CDATA[*/
is same as
<!--
|
... for all intents and purposes. However the <![CDATA[ ... ]] tags state that anything can be written inside. In XML / XHTML this is extremely important when considering that some symbols in js have different meaning in xml. For example, the double-dash at the beginning of a "normal" comment toggles between allowing the greater-than symbol (>) and using that symbol to end a comment... This is why strict comments (<! ... >) usually add a first double-dash at the beginning (making the comment start <!-- instead of <!), so that '>' can be used without ending the comment; likewise at the end of the comment, a second set of double-dashes are used to tell the parser to end the comment (thus the comment is ended with --> instead of >). However, in js, the double-dash also has meaning: as a decrimenting operator. Thus in js, you could write:
Code:
var eight=9;
eight--;
alert(eight); // '8'
Now you can begin to see the problem when using comments in strict SGML mode; the decrementing operator inside the js toggles the comment to prevent the programmer from using '>' as a greater-than symbol (and ends the comment) Thus:
Code:
var eight=9;
eight--;
if(eight>8)
// In strict SGML mode, this is no longer a part of the comment, and so will be displayed on screen!
alert(eight);
For this reason, <![CDATA[ is a better way of creating an xhtml comment, so that double-dashes and greater-than symbols can be used as intended...
This page has good test-cases and description of SGML-style comments and poblems associated with them...
__________________
If you want answers, write a
smart question.
Yes, someone probably does know how...
Oh, and if you want to learn,
STFW!