|
1 | | -// printing.js |
2 | | - |
3 | 1 | // INFO: Different Ways to Print Output in JavaScript |
4 | 2 |
|
5 | | -// 1. console.log() |
6 | | -// - Prints messages to the console with a newline. |
| 3 | +// 1. console.log() - Prints messages to the console with a newline. |
7 | 4 | console.log("Hello"); |
8 | 5 |
|
9 | | -// 2. process.stdout.write() |
10 | | -// - Writes output without adding a newline (Node.js specific). |
| 6 | +// 2. process.stdout.write() - Writes output without adding a newline (Node.js specific). |
11 | 7 | process.stdout.write("hey\n"); // Added \n for newline |
12 | 8 |
|
13 | | -// 3. console.table() |
14 | | -// - Displays objects or arrays in a table format for better readability. |
| 9 | +// 3. console.table() - Displays objects or arrays in a table format for better readability. |
15 | 10 | console.table({ city: "Islamabad" }); |
16 | 11 |
|
17 | | -// 4. console.warn() |
18 | | -// - Prints warning messages, usually highlighted in the console. |
| 12 | +// 4. console.warn() - Prints warning messages, usually highlighted in the console. |
19 | 13 | console.warn({ city: "newCity" }); |
20 | 14 |
|
21 | | -// 5. console.error() |
22 | | -// - Prints error messages, usually highlighted in the console |
| 15 | +// 5. console.error() - Prints error messages, usually highlighted in the console |
23 | 16 | console.error("The error message"); |
24 | 17 |
|
25 | 18 | /* |
26 | 19 | Note: |
27 | | -- In browsers, `console.log()`, `console.warn()`, and `console.table()` are commonly used. |
28 | | -- `process.stdout.write()` is primarily used in Node.js environments. |
| 20 | +- In browsers, console.log(), console.warn(), and console.table() are commonly used. |
| 21 | +- process.stdout.write() is primarily used in Node.js environments. |
29 | 22 | */ |
0 commit comments