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;