Javascript basics

19 February 2019   PDF version

Adding scripts to a page

We include JS code within HTML either by embedding it internally in a script tag:

console.log("embedded code")

Or by referencing an external file with the src attribute:

<script src="file.js"></script>

And then file.js would contain:

console.log("external code")

Browser console

When developing client-side (in-browser) apps in Javascript, it’s very important to check on the browser console, part of the developer tools.


Figure 1: Open the console to see error messages, log messages, to try out JS functions, and browse results


  • document.getElementById
  • document.getElementsByTagName
  • document.getElementsByClass
  • .nextElementSibling
  • .parent
  • .children

See jsdemo in the public repository in gitlab for examples.


Figure 2: @nonprofWHIT on Twitter