What happens when the delete operator cannot be used in js? How to deal with it

云罗郡主
Release: 2018-10-19 13:55:00
forward
2761 people have browsed it

What this article brings to you is about the situation where the delete operator cannot be used in js. The processing method has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

What happens when the delete operator cannot be used in js? How to deal with it

delete is a unary operator, used to delete attributes or array elements of an object. Return true or false.

Situations that cannot be deleted:

1. Use variables defined by var.

2. Built-in object properties (not configurable).

3. The function and parameters defined by the function statement.

In strict mode, deleting a non-configurable attribute will report a type error. In non-strict mode, using the delete operation returns false.

In strict mode, the specified object and its attributes must be displayed when using delete, otherwise a syntax error will be reported.

For example:

var name = "a"; window.age = 10; delete window.name;//IE<9时报错,其他浏览器返回false delete window.age;//IE<9时报错,其他浏览器返回true
Copy after login

The reason why variables declared using var cannot be deleted: The window attribute added using the var statement has a feature called configurable, and its value is set to false.



The above is a complete introduction to the situation where the delete operator cannot be deleted in js? If you want to To learn more aboutJavaScript video tutorial, please pay attention to the PHP Chinese website.

The above is the detailed content of What happens when the delete operator cannot be used in js? How to deal with it. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:csdn.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!