Shouldn't this be `if (typeof data.replacement != 'undefined')`?