What’s an elegant way to check for null values in JavaScript, especially when parsing URL parameters?

Another elegant approach is using logical AND (&&) to guard the access:

return (results && results[1]) || 0;

It returns results[1] if results exists, otherwise 0.

This is a common idiom familiar to many JavaScript developers.