javascript:; vs javascript:void(0);

Ahmed Magdy picture Ahmed Magdy · Jun 27, 2010 · Viewed 7.7k times · Source

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

Answer

Quentin picture Quentin · Jun 27, 2010

One runs JavaScript that has no statements, the other runs JavaScript that evaluates the statement 0 and then returns undefined.

Neither should be used.