02_js两个变量交换值

JavaScript两个变量交换值:

 1 <script type="text/javascript">
 2             //交换两个变量的值
 3             var number1 = 100;
 4             var number2 = 200;
 5             
 6             //方法一:定义第三个变量
 7             var number3 = number1;
 8             //再进行变量值的交换
 9             number1 = number2;
10             number2 = number3;
11             
12             //方法二:运算
13             number1 = number1 + number2;
14             number2 = number1 - number2;
15             number1 = number1 - number2;
16                 
17 </script>

 

posted @ 2020-08-05 15:18  jaysonzxk  阅读(105)  评论(0编辑  收藏  举报