1.連接符+與,的小區別
<script>
var a ="test";
document.write("this is",a);
console.log("this is",a);
alert("this is",a);
</script>
輸出
document.write: this istest
log: this is test
alert: this is
逗號在alert中不可以用於連接字符串
在console.log中自帶空格排版
write中無特殊效果
2.
<script>
var test ="test";
alert(test);
</script>
打開頁面會alert.然後將test變量刪除
<script>
alert(test);
</script>
保存,刷新頁面,依然可以alert"test".
關閉頁面,重新打開,alert爲空。
也就是說,只要頁面不關閉,代碼改變了,之前的變量也會繼續存在內存中。