The code copy is as follows:
//Create app.js page
// 1: Page code
console.log("log information");
//Execute (node app.js) on the page and see the log information in the console: "log information"
//Execute in another way: node app.js 1>info.txt (1 represents redirecting standard output stream);
//At this time, you will see an info.txt file in the same directory as the app.js, with "log information" in it.
//2: Output all strings in sequence
console.log("%s","first","second");
//Output result: first second
//3. Convert the object to a normal string and execute it
console.log("%s","guoyansi",{name:"Dr. Sisi"});
//Output result:guoyansi { name: 'Dr. Sisi' }
//Four:
//Convert string as numeric value
console.log("%d","25.6");
//Output result: 25.6
console.log("%d","guoyansi");
//Output result: guoyansi
//Five output %
console.log("%%");
//Output result:%
console.log("%%","gys");
//Output result:% gys
//Six output console.error information to the file
//Page code:
console.error("guoyansi is error");
//Use node app.js 2>err.txt to start this page
//There will be an additional err.txt file in the same level directory. There is also "guoyansi is error" in the file.
//Seven directly starts a non-existent file javascript.js on the command line, so:
// node javascript.js 2>info.txt
//Output result: There will be an extra file info.txt in the directory where the command line is located;
//The contents in the info.txt file are as follows
/*
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
*/
//Eight: The usage of console.warn is the same as console.error()
//Nine: The execution time of the intermediate code output by console.time() and console.timeEnd() (note: the parameters of time and timeEnd must be exactly the same)
console.time("for loop time:")
var a=0;
for(var i=0;i<1000000000000;i++){
a++;
}
console.timeEnd("time of for loop:")
/*
* 10.console.trace() method outputs the stack information at the current position as standard error information.
* */
var obj={
name:"guoyansi",
age:23,
eat:function(){}
}
console.trace(obj);
//Output result:
I don't know if you can understand it, but I can't understand it anyway.
1 //Ten: console.assert() evaluates the expression result. If the execution result of the expression is false, a message string is output and an AssertionError exception is thrown.
2 console.assert("g"==="s","g does not equal s");
Isn't it very simple? Uh? . Anyway, I don't feel like I can understand it, haha