javascript null value in string

How about:

var inf = [id, city].join('|');

EDIT: You can remove the "blank" parts before joining, so that if only one of id and city is null, inf will just contain that part and if both are 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

Total long shot, but try this:

var inf = (id || "") + "|" + (city || "");

var inf = (id == null ? '' : id) + '|' + (city == null ? '' : city)

Tags:

Javascript