A compiler does not check the semantics of the script. It is simply not possible for javascript. Consider this piece of code:

javascript Code:
  1. function fun(arg) { if(arg == 1) Array.prototype.foo = function() { return 7 } }
  2.  
  3. fun(userInput)
  4.  
  5. var x = Array.foo()
To copy to clipboard, switch view to plain text mode 

Depending on the external value provided from "userInput" the foo method in Array will exist or not. The script syntax is fine but its semantics may vary between runs.

A compiler, by definition, is a tool that translates a high-level program definition into a lower-level program definition that is easier to execute by the runtime environment. For example a C compiler will not bail out if you divide by 0 in your application. The runtime will.