[Debug] Debugger Statements

For example you have the following code;

function reverse(str) {
  let reversed = "";
  for (let char of str) {
    reversed = char + reversed;
  }
  return reversed;
}

module.exports = reverse;

If you want to debug is in Node, you can do:

function reverse(str) {
  let reversed = "";
  for (let char of str) {
    debugger; // add debugger
    reversed = char + reversed;
  }
  return reversed;
}

reverse("awefw"); // call the function 

module.exports = reverse;

Then in cmd, run:

node inspect index.js

Then just type 'continue' or just 'c'.

It will pause on liine of 'debugger;' Now for example you want to see, what is the variable 'str':

you can type: 'repl':

Then after you enter 'str', you will see the output.

猜你喜欢

转载自www.cnblogs.com/Answer1215/p/10903372.html
今日推荐