02. Applying JavaScript

Applying JavaScript is easy - we can apply JavaScript both internally and externally.

Internal JavaScript

JavaScript code can be placed in between the <script> tag either the head or body elements of an HTML document.

  document.write("Hello world!");

Here, we're writing the text "Hello world!" to the document. We'll learn all about the document object and its functions in the Document Object Model section.

If you plan on placeing JS code directly in your body, it's best to place it just before your </body> closing tag. This will improve page loading time since no HTML will be blocked by any of your scripts loading.

External JavaScript

It's best to keep your HTML clear of JavaScript code for readability and maintanability. An external .js file may be cached (saved on a user's computer for quick access), which can speed up page load times.

To link externally, make your external file's extension .js and link it to your document with the src attribute:

<script src="path/to/js/script.js"></script>

Build modern and responsive webpages

Responsive Typography

Build modern and responsive webpages Try Front-end

Responsive web design helps your site maintain its design integrity on a variety of screen sizes, but how does it affect your typography? With this practical book, graphic designers, web designers, and front-end developers alike will learn the nuts and bolts of how to get the best appearance from type without sacrificing performance on any device.

$ Check price
24.9924.99Amazon 4.5 logo(3+ reviews)

More Front-end resources

Aching back from coding all day?

Self-Massage Tool

Aching back from coding all day? Try Back Problems

Relieve spasms, tight muscles, trigger points and pressure points with the Body Back Buddy! This trigger point massage is designed to help you self-message any area of your body - especially those that are hard to reach. Keeping your muscles relaxes and out of contraction is importan in helping to reduce pain and prevent muscle injury.

$ Check price
29.9529.95Amazon 4.5 logo(3,443+ reviews)

More Back Problems resources