The only accurate way would be checking the property:
However, the problem with this is that in most browsers this is considered a security violation and usually just returns undefined.
Is a property that others have suggested...
However, the length doesn't work completely because it doesn't indicate where in the history you are. Additionally, it doesn't always start at the same number. IE, for example, starts at 0 while Google Chrome starts at 1 (because of the landing page).
Most of the time a link is added that calls:
and it's just expected that if you can't go back then clicking the link does nothing.