Assuming you actually want to use JavaScript within a link such as with a bookmarklet:

The javascript: protocol has a hidden feature. If a value other than undefined is passed to it, it will be interpreted as a string and (essentially) passed to document.write to build a new HTML document.

You can test this out by seeing what javascript:null and javascript:'<!DOCTYPE html><title>Hello</title> World!' do in links.

The fix for this particular issue is to make sure you never return anything to javascript:, which is why you will often see javascript:void(0) in links.

You probably don't want to use JavaScript within a link:

Rather than polluting your markup with unmaintainable JavaScript, put your script in a JavaScript file where it belongs. Also, since your link isn't being used to target a new document, use a <button> with some styles: