Three ways to use JavaScript in HTML and pros and cons

Source: Internet
Author: User

1. Internal JS: In the page directly in the <script></script> tag to write JS code

Advantages: Compared to the use of inline JS, the internal JS code is more centralized, and the page structure of the implementation of the code is less coupling, easier to maintain

Disadvantage: JS code is limited to the use of the current page, the code can not be reused by multiple pages, resulting in a high degree of code redundancy

2. External JS: Introduction of external JS file (recommended)

Advantages: 1. Page code and JS code to achieve effective separation, reduce coupling degree

2. Easy to maintain and extend the code

3. Facilitates the reuse of code

3. Inline JS: Statements nested directly in HTML

This approach is not recommended in development,

(1) Because this way with the page structure code coupling too strong, late maintenance is very inconvenient,

(2) and this way in the development process will result in a lot of redundant code

Three ways to use JavaScript in HTML and pros and cons

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.