5

Can window.location.search be null or undefined in any browser? Most of them i tried IE8/9, FF, Chrome, Safari is all empty strings.

Just want to know if i have to null check before doing string operation on it.

0

2 Answers 2

3

Should be empty strings. But using type conversion:

if(window.location.search)

will work in any case. If the search is set, it will definitely be a non empty string and evaluate to true then.

Or use typeof:

if(typeof window.location.search === "string")

but this is also true for an empty string. It depends on what you want to do in the end.

Sign up to request clarification or add additional context in comments.

Comments

0

In IE, location.search can be an empty string even though a ?key=value part is present in the URL.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.