document.getElementById("p1").style.cssText = "border:" + 1 + 1 + "px dashed green;color:red";
// 結果:border:11px ...
JS + 運算子左結合,且字串與數字相加會觸發字串連接:
"border:" + 1 → "border:1"(字串)"border:1" + 1 → "border:11"(字串連接)"px..." 仍為字串連接。document.getElementById("p1").style.cssText = "border:" + (1 + 1) + "px dashed green;color:red";
// (1+1) → 2 (數字相加) → "border:2px ..."
\`border:${1+1}px dashed green;color:red\`var w = 1+1; "border:" + w + "px...""border:" + Number(1+1) + "px..."(多餘但明確)。字串連接表達式中,任何位置出現字串會將後續 + 變為連接。需用括號隔離純數學運算,或使用模板字面量避免歧義。