console.log()node
console.log('this is a message.')
node app.js 1>info.log
//從第二個參數開始,依序輸出全部字符串 console.log('%s','hello','world') //hello world //將對象轉換爲字符後輸出 console.log('%s','hello',{foo:'world'}) //hello ({foo:'world'}) //將數值轉換爲字符串後輸出,從第二個參數開始,依序輸出全部數值 console.log('%d',10,10,5) //10 10 5 //將字符串做爲數值進行轉換,將輸出NaN console.log('%d','hello') //NaN //輸出百分號 console.log('%%','hello') //% hello
console.log('2+2') //4
console.error()app
node app.js 2> error.log
console.dir()oop
用於查看一個對象中的內容而且將該對象的信息輸出到控制檯中this
console.time()和console.timeEnd()
spa
統計一段代碼的執行時間,console.time標記開始時間,console.timeEnd標記結束時間code
兩個方法均使用一個參數,參數值爲任何字符串,但必須相同才能正確地統計出開始和結束時間所通過的毫秒數對象
console.time('small loop') for(var i=0;i<10000;i++){ ; } console.timeEnd('small loop')
console.trace()blog
用於將當前位置處的棧信息做爲標準錯誤信息輸出字符串
參數值爲任何字符串,用於標識此處輸出的標準錯誤信息io
console.assert()
用於對一個表達式的執行結果進行評估,若是該表達式的執行結果爲false,則輸出一個消息字符串並拋出AssertionError異常
console.assert(1==22,'raise an exception')