XHTML is a form of xml and conforms to the rules of XML. The browser will treat the characters < and & as xml markup, even inside a <script> tag.
As the < and & characters are also used by the JavaScript,
this creates a problem.
When your browser sees these characters in your internal javascript,
it tries to interpret the JavaScript as xml markup.
That means your page will not validate as xhtml.
You can fix this by placing the javaScript inside a CDATA section.
A CDATA section in XML/XHTML starts with the
characters <![CDATA[ and ends with the characters ]]>.
Any characters inside a CDATA tag are not treated as xml markup, which fixes the problem.
Here is an example of declaring JavaScript inside a CDATA tag.
The CDATA tag should be commented with a JavaScript comment // as in the example above.
We do this to stop JavaScript trying to interpret the CDATA tags as JavaScript, which would cause a JavaScript error.
Note: javascript imported from an external source file does not suffer from this problem.
This is one of several reasons why you should store your javascript in an external .js file and not as an inline or internal script.