Search code examples
javascriptcross-browseranchorhref

javascript:; vs javascript:void(0);


I would like to know what is the difference between javascript:; and javascript:void(0); if I use them in href attribure for a anchor (link)

<a href="javascript:;" onclick="DoSomething();">Link</a>

<a href="javascript:void(0);" onclick="DoSomething();">Link</a>

I see them acting the same on all browsers but what is the technical difference?

Regards, Magdy


Solution

  • One runs JavaScript that is just an empty statement, the other runs JavaScript that evaluates the statement 0 and then returns undefined.

    Neither should be used.