What about:
var inf = [id, city].join('|');
EDIT: You can remove the "empty" parts before joining, so if only one of id and city is null, inf will only contain that part, and if both null inf will be empty.
var inf = _([id, city]).compact().join('|'); // underscore.js var inf = [id, city].compact().join('|'); // sugar.js var inf = [id, city].filter(function(str) { return str; }).join('|'); // without helpers
source share