In general, if the url is https://www.stackoverflow.com?a=1, location.search is ?a=1
if there's no query string part, the location.search will return an empty string not '?'
why design like so
This is what the HTML spec says about location.search:
The search getter steps are:
- If
this's relevantDocumentis non-nulland its origin is not same origin-domain with the entry settings object's origin, then throw a"SecurityError"DOMException.- If this's url's query is either
nullor the empty string, return the empty string.- Return
"?", followed bythis's url's query.