debugger Statement
The debugger;
statement programmatically triggers a breakpoint.
In browsers, it pauses execution when DevTools are open; otherwise it’s ignored.
In Node.js, it pauses when an inspector is active (e.g., running with --inspect
or an attached debugger).
Syntax
debugger;
Examples
// ১) বেসিক ব্যবহার — DevTools খোলা থাকলে ব্রেক করবে
ফাংশন গুন(ক, খ) {
const ফল = ক * খ;
ডিবাগার; // এখানে থামবে
ফেরত ফল;
}
গুন(6, 7);
// ২) শর্তসাপেক্ষ ব্রেক
ফাংশন মূল্যায়ন(xs) {
জন্য (const x এর xs) {
যদি (x < 0) ডিবাগার; // নেগেটিভ দেখলেই থামাও
কনসোল.লগ("x:", x);
}
}
মূল্যায়ন([2, -1, 3]);
// ৩) async/await এর মাঝে
অসমলয় ফাংশন লোড() {
const r = অপেক্ষা fetch("/data");
ডিবাগার;
ফেরত অপেক্ষা r.json();
}
লোড();
// ৪) প্রোডাকশনে না পাঠাতে গার্ড
const DEBUG = true;
ফাংশন টেস্ট() {
যদি (DEBUG) ডিবাগার;
কনসোল.লগ("run");
}
টেস্ট();
Notes
debugger
works in both sloppy and strict mode; it’s ignored when no debugger is attached/open.- Prefer DevTools breakpoints (including conditional breakpoints) for ad‑hoc debugging; keep
debugger
for spots you want checked‑in during development. - Do not ship
debugger
to production builds — wrap with a flag or strip during bundling. - When paused, you can inspect scopes, step through, evaluate expressions, and set watch/breakpoints.
- Language aliases:
ডিবাগার
/dibagar
.