The sequence dissected. Here is what each parser sees. What is italic is a comment, what is bold is not.
HTML parser not supporting javascript
<script type="text/javascript"><!--//--><![CDATA[//><!--
{ JavaScript function removed for clarity }
//--><!]]></script>
HTML parser supporting javascript and allowing the comment kluge (strictly, <!-- is invalid javascript)
<script type="text/javascript"><!--//--><![CDATA[//><!--
{ JavaScript function removed for clarity }
//--><!]]></script>
Javascript parser in this case: sees
//--><![CDATA[//><!--
{ JavaScript function removed for clarity }
//--><!]]>
XHTML parser. Underline is CDATA tags, anything between them is not interpreted except to check for the end tag "]]>"
<script type="text/javascript"><!--//--><![CDATA[//><!--
{ JavaScript function removed for clarity }
//--><!]]></script>
What the Javascript parser is given by the XHTML parser, is this:
//><!--
{ JavaScript function removed for clarity }
//--><!
Also, make sure your script does not contain the sequences "-->" (ends the 'comment' for ancient browsers), "</script>" (ends the script tag for HTML parsers) or "]]>" (ends the CDATA block for XHTML parsers.) And, to add insult to injury, there is no browser configuration affected by any two of these [well, if you had "]]>" and then LATER a "</script>" it would affect xhtml, but that wouldn't be the only can of worms opened by closing the cdata block]
To support HTML4 and XHTML, all you need is
<script type="text/javascript">//<![CDATA[ Javascript stuff //]]></script>
Much nicer.