1.使用console.log()
console.log(object/message);
let a = 5; let b = 'asdf'; let c = a + b; // if you want to see the value of c console.log(c); // then do other operations if(c) { // do something }
在浏览器中使用 console.log() 方法会在调试器窗口中打开值。
console.log() 方法在浏览器中的工作原理
console.log() 不是特定于浏览器的。它也可用于其他 JavaScript 引擎。
2.使用调试器
let a = 6; let b = 9; let c = a * b; // stops the execution debugger; console.log(c);
让我们看看如何在 Chrome 浏览器中使用调试器。
上述程序在包含 debugger 的行中暂停程序的执行。
然后,您可以在检查程序后恢复流控制。
在控制台中按 play 键恢复脚本时,将执行其余代码。
调试器在浏览器中的工作原理
3.设置断点
在浏览器中处理断点
上一教程 :JS Regex
参考文档
[1] Parewa Labs Pvt. Ltd. (2022, January 1). Getting Started With JavaScript, from Parewa Labs Pvt. Ltd: https://www.programiz.com/javascript/debugging
发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/233996.html原文链接:https://javaforall.net