Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
Functions can be nested inside of other functions indefinitely.
Below, we encapsulate the goo function
inside of the bar function, which is
inside of the foo function.
<!DOCTYPE html><html lang="en"><body><script> var foo = function() { var bar = function() { var goo = function() { console.log(this); // logs reference to head window object }(); }(); }(); </script></body></html>
The simple takeaway here is that functions can be nested and that there is no limit to how deep the nesting can go.