Errors in synchronous js code are pretty straightforward and not unlike errors or exceptions in other languages. They can be thrown and caught, and when they are created they get a stack trace.
var fnInner = function() {
throw new Error("busted");
};
var fnOuter = function() {
fnInner();
};