The role of JavaScript window and undefined as parameters

Source: Internet
Author: User

1. Original function

Output results: 1

2, plus window parameters

Output Result: Window object

Note: Window at this time is not a global variable, but a local variable

3, about the formal parameter must pass window? Of course it's not necessary.

Output Result: Window object

A parameter can pass any character, as long as the argument passes through the window. Function

4, the function of a code will be compressed, save space

5, function two improve performance

function in the execution process, can find the window in the parameters, do not go to the global scope to find, that is, high efficiency, improve performance.

6. Is it possible to pass the argument or not?

Yes, argument parameters are not passed, internal or accessible to window, this is because window is a global variable, where it can be accessed, at this time in the global scope of the Search window, low efficiency, and the line will not be compressed.

7, why to pass in undefined?

Within the scope of the self-invocation anonymous function, ensure that undefined is truly undefined, because undefined can be overridden and assigned.

Conclusion: window is intended as an argument: improves performance and facilitates code compression.

Undefined is intended as a formal parameter: Prevents the value of undefined from being modified.

The role of JavaScript window and undefined as parameters

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.