JavaScript - some thoughts & notes

  • No relationship to Java
    (except loose one that a lot languages have by coming after C)
  • can go in body or head tho' there are some differences as to when they get loaded
     
  • <script> ... </script>

     
     
  • pull code in from another file (IN THE SAME FOLDER) with
    <script src='otherJavaScriptFile.js'></script>
  • pull code in from another file (SOMEWHERE ON THE WEB) with
    <script src='http://someserver.com/otherScriptFile.js'></script>
  • have DOM objects listen for the code by adding to their ... attributes
    <body onload="...
                  javascript goes here. NO script tags! but quotes reqired
                  ...
                 ">
                 
        <button onclick="...
                        javascript goes here. NO script tags! but quotes reqired
                        ...
                       ">
          Press Here
        </button>
                 
    TIAS - BUTTONS & OBJECTS
  • do not require trailing SEMI-COLONS however ...
          Dr Dale often will "Use them out of habit!!!"
  • debugging is still ugly but at least the different browsers can SEE the errors
          (pp.313-315 how to "turn on" the reporting in browser you are using & experiment)
          control-shift-j for Firefox
          Will only show JavaScript problems. No help at all with PHP issues.
  • Arrays use square brackets!
    topRow    = ['red', 'green', 'blue'  ]; 
    middleRow = ['cat', 'rat'  , 'donkey']; 
    bottomRow = [  1  ,    2   ,    3    ];
    
    silly = [ topRow, middleRow, bottomRow ];
    
  • operators same as for PHP except CONCATENATION which is a PLUS SIGN
  • Variables and Scoping
     
  • document.write()
    Dr Dale says "DO NOT USE
    document.write(...);
      IN FUTURE
      (There will be a better way that uses .innerHTML!)
     
  • DOM, Here's another image