Javascript occurs on the client after the JSP is already finished, so it can't be reactive to javascript actions.
That being said, the ${instances} output will be translated to a
String when used in that context, and the String will be available for the javascript comparison.
If instances IS null, it would print an empty string, not "null" and not a javascript null object. So the javascript would look like:
if(''!=null)
Which would never be true. An empty String is not a null object - even in javascript.