一、console.log("log信息");
二、console.log("%s","first","second");
輸出結果:first second
三.將對象轉換為普通字符串后執行
console.log("%s","guoyansi",{name:"思思博士"});
//輸出結果:guoyansi { name: '思思博士' }
四、
//將字符串作為數值進行轉換
console.log("%d","25.6");
//輸出結果:25.6
console.log("%d","guoyansi");
//輸出結果:guoyansi
五 輸出%
console.log("%%");
//輸出結果:%
console.log("%%","gys");
//輸出結果:% gys
六 將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文件中的內容如下
/*
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
*/
今天遇到了個大神的代碼是寫了%s,我以前還真不知道...