企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
* [ ] 实现:使用/不使用临时变量 交换两个变量的值 ``` <script> //一、使用临时变量 var n1 = 5; var n2 = 8; console.log(n1, n2); // n 临时变量 var n = n1; n1 = n2; n2 = n; console.log(n1, n2); //二、不使用临时变量 var s1 = 5; var s2 = 6; s2 = s1+s2; // s2 = 5 + 6 s1 = s2 - s1; // s1 = 11 - 5 s2 = s2 - s1; // s2 = 11 - 6 console.log(s1, s2); </script> ``` 效果: ![](https://img.kancloud.cn/a1/07/a107c23ab446e259f9aad549c5b2c3ea_629x138.png)