<!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>
运行结果