JavaScript variable declaration with Var and without var difference

Source: Internet
Author: User

The JavaScript variable declares the difference with Var and without Var:
In JavaScript, declaring variables can either use VAR or not using Var, here's a look at the difference between the two.
I. Scope differences:
Variables declared without Var are scoped globally regardless of whether they are declared inside the function.
Variables declared with VAR are global if declared outside of the function, and local variables are declared inside the function.
code example:

<type= "Text/javascript">var  A; function Fun () {  var  b;  C=ten;} </ Script >

In the above code, the scope of A and C is global, and the scope of B is local.
Two. Is it possible to delete using Delete:
variable declarations, creation properties, and properties in each JavaScript have flags that illustrate their properties----such as read-only (ReadOnly) non-enumerable (Dontenum) non-deleting (dontdelete), and so on. a variable declared without Var, which is exactly the property of the Window object, can be deleted by the delete, and the variable declared with VAR has a non-deleted attribute, so it cannot be deleted by delete.
For more information, refer to the delete operator section of JavaScript .

The original address is: http://www.softwhy.com/forum.php?mod=viewthread&tid=8177

For more information, refer to: http://www.softwhy.com/javascript/

JavaScript variable declaration with Var and without var difference

Related Article

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.