Skip to content

Commit 2da48df

Browse files
feat: add printing.js
1 parent c16fbf3 commit 2da48df

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

part1 (Basics)/09_printing.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,25 @@
1+
// printing.js
2+
3+
// INFO: Different Ways to Print Output in JavaScript
4+
5+
// 1. console.log()
6+
// - Prints messages to the console with a newline.
17
console.log("Hello");
2-
process.stdout.write("hey");
38

9+
// 2. process.stdout.write()
10+
// - Writes output without adding a newline (Node.js specific).
11+
process.stdout.write("hey\n"); // Added \n for newline
12+
13+
// 3. console.table()
14+
// - Displays objects or arrays in a table format for better readability.
415
console.table({ city: "Islamabad" });
16+
17+
// 4. console.warn()
18+
// - Prints warning messages, usually highlighted in the console.
519
console.warn({ city: "newCity" });
20+
21+
/*
22+
Note:
23+
- In browsers, `console.log()`, `console.warn()`, and `console.table()` are commonly used.
24+
- `process.stdout.write()` is primarily used in Node.js environments.
25+
*/

0 commit comments

Comments
 (0)