Home  >  Article  >  Web Front-end  >  What happens when the delete operator cannot be used in js? How to deal with it

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

云罗郡主
云罗郡主forward
2018-10-19 13:54:062841browse

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

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 about JavaScript 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!

Statement:
This article is reproduced at:csdn.net. If there is any infringement, please contact admin@php.cn delete