Conditional breakpoint ( or edit breakpoint) in VS code debugging is not working

2.1k Views Asked by At

I'm trying to use conditional breakpoint like 'lessThan5' is executed if n is 3 and 'greaterThan5' is executed if n is 10.

(Please excuse this so simple example. It was just made for asking question to solve other problem)

function lessThan5(n){
  console.log('less than 5');
}

function greaterThan5(n){
  console.log('greater than 5');
}


function checkNum(n){
  if(n < 5 ){
    lessThan5();
  } else {
    greaterThan5();
  }
}

checkNum(n);

I tried 'Add breakpoint' in VScode at checkNum(n) and change n to 3 with 'Expression in Edit breakpoint'. But I got 'ReferenceError: n is not defined'. I guess I've searched almost everything about editting breakpoint but it didn't work.

Is there any possible way to insert conditional input in VS code debug mode?

1

There are 1 best solutions below

0
Mark On

It isn't clear to me exactly what you are trying to do, but here is how you could set a conditional breakpoint at checkNum(n):

conditional breakpoint

Then you call checkNum(<someValue>) like checkNum(11) and the debugger will stop at your conditional breakpoint since (n < 5) || (n > 10) returns true.