1.宣告變數
var name = "Tom"; // 舊方式,不建議
自動 // 舊方式,不建議
let age = 20; // 區塊作用域
const PI = 3.14; // 常數 (不可重新指定)
let x = 10;
x = 20; // OK
const y = 30;
// y = 40; ❌ 錯誤 (不能重新指定)
let userName = "Tom";
let totalScore = 100;
<!DOCTYPE html>
<html>
<body>
<p id="demo"></p>
<script>
let carName = "紅姊";
document.getElementById("demo").innerHTML = carName;
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<body>
<p id="demo"></p>
<script>
const price1 = 1234;
const price2 = 5678;
let total = price1 + price2;
document.getElementById("demo").innerHTML = "The total is: " + total;
</script>
</body>
</html>