此外,一些日志记录工具或浏览器控制台可能会以不同的方式处理console.error和console.log的输出,使得cons...
console.log('文字信息');console.info('提示信息');console.warn('警告信息');console.error('错误信息'); 分组输出 使用Console.group()和Console.groupEnd()包裹分组内容。 还可以使用Console.groupCollapsed()来代替Console.group()生成折叠的分组。 console.group('第一个组');console.log("1-1");console....
2.console.info 与console.log作用基本上一致,仅在 Firefox浏览器中,web 控制台的日志中的项目旁边会显示一个小的‘I‘图标。 console.info('info打印'); // info打印 3.console.warn 在控制台中输出一条警告信息 console.warn('warn信息'); // warn信息 4.console.error 在控制台中输出一条错误信息 conso...
console.error("error message"); group(title) 对发送到控制台窗口的消息开始分组,并发送可选的 title 作为组标签。 在控制台窗口中,组可以嵌套并显示在树视图中。 在某些情况下,例如使用一个组件模型时,通过 group* 命令可以更轻松地查看控制台窗口输出。
(1)console.log() 打印 123console.log('hello');45 在浏览器中运行打开 (2) console.info() 信息 console.info('信息'); 在浏览器中运行打开,直接打印内容 (3) console.error() 错误 console.error('错误'); 在浏览器中运行打开,显示类似于报错的消息...
JavaScript 提供了一个标准的 Error 对象来管理错误,但在实际开发中,通常需要针对特定场景定制错误处理。这时,自定义错误和扩展 Error 类就显得尤为重要。 1. Error 对象的基础 在JavaScript 中,Error 对象是所有错误处理的基础。创建一个错误非常简单: const error = new Error("发生了某些错误!"); console.log(...
console.log(a) }catch(error) { // 打印错误信息 console.log(error) // ReferenceError: a is not defined } 1. 2. 3. 4. 5. 6. throw,用来抛出一个用户自定义的异常,执行将被停止。 function getUserName(name) { if(!name) throw new Error('用户名无效'); ...
console.log(err.name); console.log(err.message); console.log(err.stack); 1. 2. 3. 4. 打印结果如下: error的name属性值是可以改变的,如下: var err = new Error('i was wrong information'); err.name = 'wrong'; console.log(err.name);//结果为wrong ...
console.log('Console Log') console.info('Console Info') console.debug('Console Debug') console.warn('Console Warn') console.error('Console Error') These variations add styling to our logs in the console. For instance, the warn will be colored yellow, and the error will be colored red. ...
windows下面的全局error事件程序,当有javaSript脚本运行错误或者资源、加载失败时,都会触发Event接口的error事件,也能被window.addEventListener捕获到 两种写法 window.onerror = function(message, source, lineno, colno, error) { console.log(message)//字符串错误信息 console.log(source...