Error.prototype.stack cung cấp **stack trace**: chuỗi mô tả call stack tại thời điểm throw error — function nào gọi function nào, dòng nào, file nào, arguments gì.
Ví dụ
function a() { throw new Error("error"); }
try { a(); } catch(e) { console.log(e.stack); }
Output mẫu
Error: error
at a (:2:11)
at :6:5
Đặc điểm
- Từ recent calls → earlier calls → global scope.
- Format khác nhau giữa engine (V8, SpiderMonkey, JavaScriptCore).
- Non-standard — không nằm trong ECMAScript spec. Có thể không có trong một số env (embedded JS, old IE).
Use case
- Debug production error (logging service: Sentry, LogRocket...).
- Error boundary trong React/Vue.
- Development: console.error tự động in stack.