前端學習(623):交換兩個變量的值

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>交換兩個變量的值</title>
</head>
<body>
    <script>
        /* 1我們需要一個臨時變量來做 把app1給我們的臨時變量給temp
        2把app2的蘋果給app1
        3把臨時變量的值給app2
        */
       /* 臨時變量爲空 */
       var temp;
       var app1='青蘋果';
       var app2='紅蘋果';
       temp = app1;//把右邊給左邊
       app1 = app2;
       app2 = temp;
       console.log(app1);
       console.log(app2);

    </script>
</body>
</html>

運行結果

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章