Why need I to do a ternärer operator in a variable?

Why need I to do a ternärer operator in a variable?

This works for me:(inline in a svg)
function() {var query = ((this.id) == 'value') ? 'twittername1' : 'twittername2'; top.location.href='http://twitter.com/'+query}

but not
function() { top.location.href='http://twitter.com/'+((this.id) == 'value') ? 'twittername1' : 'twittername2';}

Why this?