If `msg.id` is undefined then `id` becomes `'undefined'`. Perhaps `var id = (msg.id) ? msg.id.toString() : undefined;` would be better.