Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
var a = 1, b = 9; a, b = b, a; console.log(a,b) 1 9
割り当てが左から右の順序で実行された可能性はありますか? したがって、「a」は「b」の値を取り、「b」は「a」の値を取ります。
値の交換は非常に簡単です。
var temp = b; b = a; a = temp;
編集:整数がすべての場合、追加の変数がなくてもスワッピングが発生する可能性があります:
b = b - a; a = a + b; b = a - b;