In some cases where Javascript is processed or handled -- for example when the code is embedded into an HTML page -- the character sequences </script
and <script
are processed separately, before the Javascript is parsed to identify string constants and the like.
Therefore it is more robust to make sure that Javascript code one writes never contains these character sequences. It is arguably a good defensive habit to do this even for code that is not currently being processed by systems that would be broken by </script>
-- because that will prevent problems in case the code is later copy-pasted into a context where </script>
does produce a problem.