zoukankan      html  css  js  c++  java
  • [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.

  • 相关阅读:
    Git
    Git
    Git
    Git
    Docker
    Linux
    Linux
    Python
    Python
    SQL
  • 原文地址:https://www.cnblogs.com/Answer1215/p/10903372.html
Copyright © 2011-2022 走看看