Summary of console usage in JavaScript or node

Source: Internet
Author: User
Tags file info

1 //Create App.js page2 //One: page code3Console.log ("Log Information");4 //Execute (node app.js) in the page this file will see the log message in the console: "Log Information"5 //execute in another way: node App.js 1>info.txt (1 for redirect standard output stream);6 //this time you will see a info.txt file in App.js's sibling directory, with "log information" in it.7 8 //two: Output all strings sequentially9Console.log ("%s", "First", "second");Ten //output Result: First Second One  A //three. Execute after converting an object to a normal string -Console.log ("%s", "Guoyansi", {name: "Dr. Sisi"}); - //output: Guoyansi {name: ' Dr. Sisi '} the  - //Four: - //Convert a string as a numeric value -Console.log ("%d", "25.6"); + //output Result: 25.6 -Console.log ("%d", "Guoyansi"); + //output Result: Guoyansi A  at //Five output% -Console.log ("percent"); - //output Result:% -Console.log ("percent", "Gys"); - //output Result:% Gys -  in //VI output CONSOLE.ERROR information to a file - //page code: toConsole.error ("Guoyansi is Error"); + //start this page with node App.js 2>err.txt - //There is one more Err.txt file in the sibling directory. There is also "Guoyansi is Error" in the file the  * //Seven start a file javascript.js that does not exist directly on the command line, such as: $ //node Javascript.js 2>info.txtPanax Notoginseng //output: One more file Info.txt in the directory where the command line is located; - //the contents of the Info.txt file are as follows the  +  A /* the 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) the At startup (node.js:119:16) - At Node.js:906:3Wuyi  */ the  - //Eight: The use of Console.warn is the same as the use of Console.error () Wu  - //Nine: Console.time () and console.timeend () outputs the execution time of the intermediate code (note: The parameters of the timing and timeend must be exactly the same) AboutConsole.time ("For Loop Time:") $ varA=0; -  for(vari=0;i<10000000000000;i++){ -a++; - } AConsole.timeend ("For Loop Time:") + /* the * The 10.console.trace () method outputs the stack information at the current location as a standard error message. -  *  */ $  the varobj={ theName: "Guoyansi", theAge:23, theEatfunction(){} - } in console.trace (obj); the //Output Result:

I don't know if you can read it, I can't understand it anyway.

1 // 10: Console.assert () evaluates the expression result, if the expression evaluates to False, Outputs a message string and throws a Assertionerror exception

2 console.assert ("g" = = = = "S", "G not equal to S");

Summary of console usage in JavaScript or node

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.