05JS advanced methods do not have block-level scopes

Source: Internet
Author: User

<! DOCTYPE html>//the 1.js top-level scope is window        varnum = 1;        alert (window.num); //2 Method Scope        functionTest () {number2= 2;//when you declare a local variable inside a method, you need to add var or the global variable            varNUM3 = 3;//Local variables cannot be accessed outside the method            //3 No block-level scope             for(vari = 0; I < 10; i++)            {                varNUM4 = 4; } alert (NUM4); //because there is no block-level scope, the variable num4 here is a local variable of the method} test ();    alert (WINDOW.NUMBER2); </script>

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.