Let's talk about the execution of functions with the same name and variables in js.

Source: Internet
Author: User

Let's talk about the execution of functions with the same name and variables in js.

It is tested that functions of the same name defined in the same file or in different js files are not written in the form of closures. During the call, a function defined later is executed. Even in this case, the execution of the following code will pop up 2:

<Script type = "text/javascript"> function t () {alert (1) ;}t (); function t () {alert (2) ;}</script>

In addition,Variables and css styles are also subject to the future.

However, if a function is written in this way, 1 is displayed when the preceding function is executed. I do not know why.

<Script type = "text/javascript"> var t = function () {alert (1);} function t () {alert (2);} t (); </script>

The above discussion about the execution of functions with the same name and variables in js is all the content that I have shared with you. I hope to give you a reference and support for the help house.

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.