This page was translated from English by the community.Learn more and join the MDN Web Docs community.
SyntaxError: applying the 'delete' operator to an unqualified name is deprecated
메세지
SyntaxError: Calling delete on expression not allowed in strict mode (Edge) SyntaxError: applying the 'delete' operator to an unqualified name is deprecated (Firefox) SyntaxError: Delete of an unqualified identifier in strict mode. (Chrome)
In this article
에러 타입
엄격(Strict) 모드에서의SyntaxError
무엇이 잘못되었을까?
JavaScript에서 일반 변수는delete 연산자를 사용하여 삭제할 수 없습니다. 엄격 모드에서 변수를 삭제하는 접근은 허용되지 않으므로 에러가 발생합니다.
delete 연산자는 오직 객체의 속성만을 삭제할 수 있습니다. 객체 속성은 설정할 수 있는 경우 "수식"될 수 있습니다.
일반적인 생각과 다르게delete 연산자는 메모리 해제와 직접적인 연관이 없습니다. 메모리 관리는 참조가 깨짐에 따라 간접적으로 수행됩니다. 자세한 내용은메모리 관리 페이지와delete 연산자 페이지를 참조하십시오.
이 에러는 오직엄격 모드 코드에서만 발생합니다. 엄격하지 않은 모드에서 해당 연산자는 단순히false 를 반환합니다.
예제
JavaScript에서 일반 변수를 삭제하려고 하면 동작하지 않습니다. 그리고 엄격 모드에서는 에러가 발생합니다:
js
"use strict";var x;// ...delete x;// SyntaxError: applying the 'delete' operator to an unqualified name// is deprecated변수의 내용을 비우려면null을 설정하면 됩니다:
js
"use strict";var x;// ...x = null;// x는 가비지 컬렉터에 의해 메모리에서 해제됩니다