[javascript] What does href expression <a href="javascript:;"></a> do?

It's used to write js codes inside of href instead of event listeners like onclick and avoiding # links in href to make a tags valid for HTML.

Interesting fact

I had a research on how to use javascript: inside of href attribute and got the result that I can write multiple lines in it!

<a href="
     javascript:
        a = 4;
        console.log(a++); 
        a += 2; 
        console.log(a++); 
        if(a < 6){ 
            console.log('a is lower than 6');
        } 
        else 
            console.log('a is greater than 6');
        function log(s){
            console.log(s);
        }
        log('function implementation working too');

">Click here</a>
  • Tested in chrome Version 68.0.3440.106 (Official Build) (64-bit)

  • Tested in Firefox Quantum 61.0.1 (64-bit)