There are three types of code in Ecmascript:
- Global code
Source text that's an Ecmascript Program. Note that this does NOT include source parsed as Function code.
- Eval code
Any string that's fed to eval, setTimeout and setInterval. It will be parsed as the global code for that Program.
- Function code
Code parsed as part of the FunctionBody. Does not contain the code of a nested FunctionBody. It's also the value provided as the last parameter to the built-in Function constructor.
Examples:
var x = 5;
debugger(x);
var hello = function(y){
return Math.floor(y);
};
debugger(y(3.4));
function moar(z) {
return Math.pow(z,2);
}
debugger(z(12.3));
eval("debugger(hello(25)===moar(5));");
So there are two Programs here:
var x = 5;
debugger(x);
var hello = function(y){};
debugger(y(3.4));
function moar(z) {}
debugger(z(12.3));
eval("debugger(hello(25)===moar(5));");
And the eval code...
debugger(hello(25)===moar(5));
Note that the eval Program is still part of the main Program, because it hasn't parsed it beforehand. You could argue that the eval Program also doesn't exist at that point. Fine. :)
There are two FunctionBodies:
return Math.floor(y);
and
return Math.pow(z,2);