delete
運算子delete
會回傳 false
,但語法本身仍可以被接受。錯誤類型:TypeError: Cannot delete property 'prototype' of function Object() { [native code] }
eval
或 arguments
作為變數名稱eval
和 arguments
是 JavaScript 的關鍵字,各自另有用途,拿來作變數名稱容易導致非預期的結果。錯誤類型:SyntaxError: Unexpected eval or arguments in strict mode
interface
、public
、private
、package
等,在其他程式語言都是很重要也很普遍的關鍵字。錯誤類型:TypeError: Cannot assign to read only property 'articleTarget' of object '#<Object>'
eval()
宣告的變數或函數,不能在該 Scope 被語法呼叫使用eval()
宣告的時候拋錯,而是後續想使用的時候拋錯,而且拋出的錯誤類型是 ReferenceError
。eval()
內自己宣告自己使用也沒有問題,後續想用語法去呼叫使用才會拋錯。eval()
所執行的語法會自成一個暫時的 Scope,在裡面宣告的變數或函數都只屬於這個 Scope。ReferenceError
類型的錯誤。錯誤類型:ReferenceError: x is not defined
eval()
內自己宣告自己使用並沒有問題:with
語法with
語法。錯誤類型:SyntaxError: Strict mode code may not include a with statement
this
代表的物件不一樣this
,指的是 Global Object。this
,變成 undefined
。let
或 const
來取代 var
,就可以限制變數重複宣告。use strict
!