4. Using JS #

Created Wednesday 08 July 2020

In the browser #

There are 2 ways to add JS code:

  1. Add it as content of the script tag.
    <!-- Method 1, direct -->
    <body>
    <script> var x = 2; </script>
    <body>
    
  2. Add code from a .js file using src attribute. script is still a content tag.
    <!-- Method 2, src -->
    <body>
    <script src="path"></script> <!-- Leave tag content empty -->
    <body>
    

Note:

In the terminal #

REPL #

Differences #