|
| 1 | +/*** |
| 2 | + * The goal of this file is to know about the console functions; |
| 3 | + * Used for printing standard outputs and errors. Similar to the console object |
| 4 | + * functions provided by most of the web browsers. |
| 5 | + * |
| 6 | + * How to run this example: |
| 7 | + * 1. node console.js |
| 8 | + * 2. See the message get displayed on prompt. |
| 9 | + */ |
| 10 | + |
| 11 | +/*** |
| 12 | + * console.log([arg1],...); |
| 13 | + * Note: Prints to stdout with newline. This function can take multiple arguments. |
| 14 | +*/ |
| 15 | +console.log("Hi, My name is Ashwin Hegde"); |
| 16 | + |
| 17 | +var designation = "Web Developer"; |
| 18 | +console.log("I am " + designation + " at Cybage Software Private Limited, Pune, HQ"); |
| 19 | + |
| 20 | +var experience = 2.6; |
| 21 | +console.log("I have total %d of Experience", experience); // %d is for both Integer & Float. |
| 22 | + |
| 23 | +var languages = { |
| 24 | + "lang1": "JavaScript", |
| 25 | + "lang2": "PHP", |
| 26 | + "lang3": ".NET", |
| 27 | + "lang4": "Java", |
| 28 | + "lang5": "Ruby", |
| 29 | + "lang6": "Python" |
| 30 | +} |
| 31 | +console.log("Printing output when used to print JSON Object via %s: ", languages); // %s for String |
| 32 | +console.log("Printing output when used to print JSON Object via %j: ", languages); // %j for JSON |
| 33 | + |
| 34 | +console.log("%s is Awesome.", "node"); |
| 35 | + |
| 36 | +/*** |
| 37 | + * Same as console.log |
| 38 | +*/ |
| 39 | +console.info("Info: Information Message"); |
| 40 | +console.warn("Warn: Warning Message"); |
| 41 | + |
| 42 | +/*** |
| 43 | + * Same as console.log but prints to stderr. |
| 44 | +*/ |
| 45 | +console.error("Error: Error Message") |
| 46 | + |
| 47 | +/*** |
| 48 | + * console.time() will mark a time. |
| 49 | + * console.timeEnd() will finish timer, record output. |
| 50 | +*/ |
| 51 | +console.time('Time-Calculations'); |
| 52 | +for (var i = 0; i < 1000000000; i++) { |
| 53 | + ; |
| 54 | +} |
| 55 | +console.timeEnd('Time-Calculations'); |
0 commit comments