1、console.log("log信息");javascript
2、console.log("%s","first","second");java
輸出結果:first secondnode
三.將對象轉換爲普通字符串後執行
console.log("%s","guoyansi",{name:"思思博士"});
//輸出結果:guoyansi { name: '思思博士' }app
4、命令行
//將字符串做爲數值進行轉換
console.log("%d","25.6");
//輸出結果:25.6
console.log("%d","guoyansi");
//輸出結果:guoyansi對象
五 輸出%
console.log("%%");
//輸出結果:%
console.log("%%","gys");
//輸出結果:% gysip
六 將console.error信息輸出到文件中去
//頁面代碼:
console.error("guoyansi is error");
//利用node app.js 2>err.txt啓動這個頁面
//會在同級目錄下多一個err.txt文件.文件裏面還有"guoyansi is error"字符串
七 直接在命令行啓動一個並不存在的文件javascript.js,這樣:
// node javascript.js 2>info.txt
//輸出結果:會在命令行所在的目錄下多出一個文件info.txt;
//info.txt文件中的內容以下io
/*
module.js:340
throw err;
^
Error: Cannot find module 'E:\node\gys\javascript.js'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:906:3
*/console
今天遇到了個大神的代碼是寫了%s,我之前還真不知道...