Console.log is there a way to name sent variables?

后端 未结 3 1838
死守一世寂寞
死守一世寂寞 2021-01-24 20:28

When sending items to console.log is there a way to name them? Similar to \"watch\" in visual studio

for example we have a var counter=1; so that in the co

3条回答
  •  再見小時候
    2021-01-24 20:53

    Not directly, but you can just name them when you output them.

    console.log (and .error, .info, and .warn) let you pass any number of values at the same time, so it's super easy to just do something like this:

    console.log('counter', counter);
    

    which would output like:

    counter 1
    

    let counter = 0;
    
    for (let i = 0; i < 5; i++) {
      counter++;
      console.log('counter', counter);
    }

提交回复
热议问题