Javascript plus operator not works with ternary if else
问题 Hi this is my js code. var a = '<span> and have </span>' + $('#module_product_review_star_1 .pdp-link')[1] ? $('#module_product_review_star_1 .pdp-link')[1].outerHTML : 'not have'; alert(a); I'm using ternary operator to check the item exists in dom. But when the item is not in dom this code is failing. this works, if($('#module_product_review_star_1 .pdp-link')[1]){ questiones = '<span> and have </span>' + $('#module_product_review_star_1 .pdp-link')[1].outerHTML; } But I need to use ternary