Best practice for asserting a positive IF condition
You should NEVER! add superfluous or unused code.

Your code should have the single if statement checking for not equal.

    const href = element.getAttribute('href');
    if (href.indexOf('#') !== 0) {
        element.setAttribute('target', '_blank');
    }


or better yet avoid the overly complex referencing via get set attribute, and not using a search to find a known location state the whole thing becomes.

    if (element.href[0] === "#") { element.target = "_blank" }


And as a whole there is a huge amount of noise that can be removed

dom.window.document.querySelectorAll("a")
   .forEach(el =&gt; el.href[0] === "#" &amp;&amp; (el.target = "_blank"));