Skip to article frontmatterSkip to article content
tools = require('../js/tools'); tools.init()
Loading...

why JavaScript

JavaScript comes in addition to

JavaScript

JavaScript characteristics

page loading - asynchronism

reminder : a few orders of magnitude

a simple page

when loading the simplest possible page, contents get scattered into packets, so it does not arrive all at once

a page with a nested page

in the case of a page that has a nested page (e.g. a CSS style), there are 2 HTTP requests at work

loading a real page

Devel Tools can visualize the actual loading workflow

JS loading - howto

open topic

simplest case

for our use case, it’s simple: a single HTML page needs to load one JS fragment
there is one simple way : the <script> tag, that comes in 2 flavours:

<script src="..."> : load a URL

most often though, code is stored in a separate location

for that, use <script src="some-url"></script>

<script> with inline code

<script>

  function hello() {
    console.log("Hello world");
  }

  hello()

</script>

practice


now that you know how to inject JavaScript code in your html page, let’s see a few examples that use JS

example #1

in the following example :

Loading...

ex1 - takeaways (1)

ex1 - takeaways (2)

about visibility of symbols (variable and function names) :

example #2

in this further example :

Loading...

ex2 - takeaways (1)

ex2 - takeaways (2)

ex2 - takeaways (3)

ex2 - takeaways (4)

example #3

in this further example :

Loading...

ex3 - takeaways (1)

let’s wrap it up

event-driven

callbacks

the historical paradigm for event-driven programming :

in our 3 examples, we have seen 4 callbacks already

take home message

as far as Web frontend, JavaScript :

see also: JS vs Python

an interesting summary of the similarities and differences between JavaScript and Python can be found here
https://observablehq.com/@ballingt/javascript-for-python-programmers