console.log()是web开发人员工作中的好朋友。但是你知道控制台包含的不仅仅是console.log()吗?这篇文章要讨论的就是JavaScript中的控制台。0 W7 w8 |8 A1 M1 N' Y 简介1 c+ s' g' F: s% T9 @
Web控制台是一个工具,主要用于记录与网页相关的信息,例如:网络请求、JavaScript安全错误、警告、CSS等。它使我们能够通过在网页内容中执行JavaScript表达式来与网页交互。5 y$ l. \! ^, T2 H' `1 f' b' A9 g% E2 s
控制台的类型 : n3 ~/ C, m+ h* ?7 k
console.log()
console.error()
console.warn()
console.clear()
console.time()
console.table()
console.count()
console.group() ; K% f# n! ]% b' Q5 d
1. console.log()# ~0 e# I3 w9 e2 J/ n. O; j7 P! B
主要用于将输出信息打印到控制台。log()中可以放入任何类型,无论是强类型、数组、对象、还是布尔值等。 * b" T4 _* d1 n
// console.time() and console.timeEnd() method
// console.time() method
console.time("Let's see time console")
let time1 = function(){
console.log('time1 function is running')
}
let time2 = function(){
console.log('time2 function is running')
}
time1()
time2()
// console.timeEnd() method
console.timeEnd('Time Taken')
$ s3 X" P% K4 m+ m, z6 Z) B6. console.table() ! V1 G& K# U" l4 y) a) e4 o$ b9 P$ L这个方法允许我们在控制台中生成表格。输入数据必须是数组或显示为表格的对象。 9 z K- ?8 [! ]1 t: ^* L3 I5 u
// console.group() and console.groupEnd() method
// console.group() method
console.group('This is a sample group')
console.log('This is a sample group log')
console.warn('This is a sample group warning')
console.error('This is a sample group error')
// console.groupEnd() method
console.groupEnd('This is a sample group')
console.log('This is a new section')