[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.

posted @ 2019-05-21 23:59  Zhentiw  阅读(270)  评论(0)    收藏  举报