JavaScript var variable delete

Source: Internet
Author: User

VAR has three types of claims:

    1. Global variables declared by Var

    2. var declared local variables within the scope of a function

    3. The global variable declared in eval.

First of all

1, 2 cases Var declares that the variable cannot be deleted.

Although the global variable declared by Var is a property of the Window object (in the browser), it cannot be deleted because of the configurable=false of this property and therefore cannot be dropped.

Not to mention the local variables, even the var variable dependent object does not know where, certainly cannot delete.

While Eval (' var a = 1 ') appears to be the same effect as direct Var (which is, of course, performing eval in the global role), and an A property is created on the Window object after execution, but this property is configurable=true and therefore can be deleted.

<script type= "Text/javascript" >varA = 1; Console.log (object.getownpropertydescriptor (window,' a '));//falseAa=1; Console.log (object.getownpropertydescriptor (window,' AA '));//true     with({}) {        varb = 1; Console.log (object.getownpropertydescriptor (window,' B '));//falseConsole.log (Deleteb); } eval (' var c = 1 '); Console.log (object.getownpropertydescriptor (window,' C '));//true</script>

function cannot be deleted

Functions in local scopes cannot be deleted.

The author starof, because the knowledge itself in the change, the author is also constantly learning and growth, the content of the article is not updated regularly, in order to avoid misleading readers, convenient tracing, please reprint annotated source: http://www.cnblogs.com/starof/p/4904929. HTML has a problem welcome to discuss with me, common progress.

JavaScript var variable delete

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.