<!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>
運行結果