交换两个变量
1 <script type="text/javascript"> 2 /*借助第三方变量*/ 3 var temp = 0; 4 var a = 1; 5 var b = 2; 6 console.log("a:"+a+"----"+"b:"+b); 7 temp = a; 8 a = b; 9 b= temp; 10 console.log("a:"+a+"----"+"b:"+b); 11 12 13 /*不借助第三方*/ 14 var a = 10; 15 var b = 20; 16 console.log("a:"+a+"---"+"b:"+b); 17 a = a + b; 18 b = a - b; 19 a = a - b; 20 console.log("a:"+a+"---"+"b:"+b); 21 </script>