client side scripts producing non-valid HTML that validates
===

I noticed using JavaScript I can produce HTML with mismatching tags that still pass the [w3 validator][1]. For example  

    <script type="text/javascript>
    document.write("<h4>This is large text<h2></h4> This is small text")
    </script>
  
has unnested `</h4>` and no closing `<h2>` but the document still passes as HTML 5 (or whatever). Can this be an issue regarding browser compatibility and why is it not detected?


  [1]: http://validator.w3.org/check