Where to Insert JavaScript

  1. Header or Body, use <script> ... </script>

    1
    2
    3
    <script>
    function myFunction() {}
    </script>
  2. External File or URL, use <script src="..."></script>

    1
    2
    <script src="/js/myScript.js"></script>
    <script src="https://www.dummy.com/js/myScript.js"></script>

JavaScript Output

  1. to Document: document.write("...")
  2. to Element: document.getElementById("elementName").innerHTML = ...
  3. to Alert Window: window.alert(...); alert(...)
  4. to Console: console.log(...)

JavaScript Syntax

I know C, so nothing new

JavaScript Statements

  1. “;” is not required, but recommended
  2. line break after operator?????
  3. use function as code blocks
  4. keywords:
    1. break, continue, do ... while, for, if ... else, return, switch similar to C
    2. try ... catch similar to java
    3. debugger: Stops the execution of JavaScript, and calls (if available) the debugging function
    4. function, var explained above

JavaScript Comments

Nothing new here

JavaScript Variables