【小問題】js連接符,+;變量的保存。

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爲空。

也就是說,只要頁面不關閉,代碼改變了,之前的變量也會繼續存在內存中。

發佈了39 篇原創文章 · 獲贊 37 · 訪問量 10萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章