You can simply do if (!responseDialog.length) {