I would like to check if the current page has an anchor
so I am using this
var qs = window.location.hash;
then checking if qs is not an empty string
if (qs !== '') {
Is this the correct way to do that? It seems to work, but I am confusing myself reading about JavaScript’s various ways to check for null/undefined/empty string.
window.location.hashonly contains inner page links/anchors (those that follow a hash (#) symbol)window.location.searchcontains the query string with a?prefixUsing your conditional (if-statement) is fine. If the property is not populated it will be a blank string.