JS TutorialLesson 2Free preview
JS Where To
This lesson is part of JavaScript · All levels
Summary
JavaScript can be written directly into HTML using the <script> tag or separated into an extensive .js file loaded with the src attribute. External code separation makes files more neat, easier to cache in a browser, and easier to share with multiple pages. Positions and attributes such as defer and async determine when a script is executed relative to the page parsing process.
Key points
- <script> tags are used to write or load JavaScript in HTML
- External script is loaded with <script src='app.js'></script>
- The defer attribute delays execution until the HTML parsing is complete, while the async runs the script once it is completed downloading
- Put the script at the end of <body> so that the elements are already available when the code is running
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.