請(qǐng)問 name 是保留字么,為什么用name做為數(shù)組名是會(huì)出現(xiàn)錯(cuò)誤,var name = ["小A",'小B','小C','小D','小E','小F','小G','小H','小I','小J'];用document.write輸出時(shí)name[0]=小 name[1]=A name[2]=, ?等等求解答
關(guān)鍵字:
var new deleteinstanceof typeof
try catch finally throw
switch case break default
void return
if else
for in do while
保留字:
goto
debugger throws
import export
private public protected
package class interface implements extends super
short byte int long float double boolean char enum
static const volatile final abstract transient
native synchronized
2016-09-29
這里的name 已經(jīng)被瀏覽器裝換成了 string對(duì)象, ?name[1] 實(shí)際訪問的是第二個(gè)字符 即A
2016-09-29
但是如果上面那個(gè)是正確的答案的話 不知道為什么 name屬性不可以通過重新賦值來改變。。。
2016-09-29
得到的最靠譜的答案:
window下面默認(rèn)有個(gè)變量叫name
window.name???默認(rèn)類型是string
2016-09-29
JavaScript關(guān)鍵字和保留字:
關(guān)鍵字: var new deleteinstanceof typeof try catch finally throw switch case break default void return if else for in do while 保留字: goto debugger throws import export private public protected package class interface implements extends super short byte int long float double boolean char enum static const volatile final abstract transient native synchronized
雖然不知道原因到底是什么,但是測(cè)試了一下,確實(shí)如一樓所說,name里面的東西除了單引號(hào),被當(dāng)成了一整個(gè)字符數(shù)組,比如name[3]打印的就是“小”。而改成names之后,會(huì)被正常的當(dāng)做字符串?dāng)?shù)組,names[1]輸出小B。后面有了答案再交流~