Skip to content

Commit 0326a03

Browse files
committed
Add examples
1 parent 3b62d8f commit 0326a03

File tree

4 files changed

+112
-0
lines changed

4 files changed

+112
-0
lines changed

JavaScript/1-console.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
'use strict';
2+
3+
console.log('log');
4+
5+
const obj = {
6+
name: 'Marcus Aurelius',
7+
city: 'Roma',
8+
born: 121,
9+
children: [
10+
{
11+
name: 'Vibia Aurelia Sabina',
12+
city: 'Sirmium',
13+
born: 170,
14+
},
15+
{
16+
name: 'Annia Cornificia Faustina Minor',
17+
city: 'Roma',
18+
born: 160,
19+
}
20+
]
21+
};
22+
23+
Object.defineProperty(obj, 'childCount', {
24+
enumerable: false,
25+
writable: false,
26+
value: 13
27+
});
28+
29+
console.log({ obj });
30+
31+
console.dir({ obj });
32+
console.dir({ obj }, { showHidden: true, depth: 20, colors: true });
33+
34+
console.error('Error');
35+
36+
console.time('Loop time');
37+
const arr = [];
38+
for (let i = 0; i < 10000; i++) {
39+
arr.push(i);
40+
}
41+
console.timeEnd('Loop time');
42+
43+
console.trace('Treace here');

JavaScript/2-readline.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
'use strict';
2+
3+
const readline = require('readline');
4+
5+
const rl = readline.createInterface({
6+
input: process.stdin,
7+
output: process.stdout
8+
});
9+
10+
rl.question('Enter your name: ', (name) => {
11+
console.log(`Hello ${name} !`);
12+
rl.close();
13+
});

JavaScript/3-prompt.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
'use strict';
2+
3+
const readline = require('readline');
4+
5+
const rl = readline.createInterface({
6+
input: process.stdin,
7+
output: process.stdout,
8+
prompt: '> '
9+
});
10+
11+
rl.prompt();
12+
13+
const commands = {
14+
help() {
15+
console.log('Commands: ' + Object.keys(commands).join(', '));
16+
},
17+
hello() {
18+
console.log('Hello there!');
19+
},
20+
exit() {
21+
rl.close();
22+
}
23+
};
24+
25+
rl.on('line', (line) => {
26+
line = line.trim();
27+
const command = commands[line];
28+
if (command) command();
29+
else console.log('Unknown command');
30+
rl.prompt();
31+
}).on('close', () => {
32+
console.log('Bye!');
33+
process.exit(0);
34+
});

JavaScript/4-cli.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
'use strict';
2+
3+
console.dir({
4+
currentDirectory: process.cwd(),
5+
processId: process.pid,
6+
platform: process.platform,
7+
release: process.release,
8+
title: process.title,
9+
nodeVersion: process.version,
10+
versions: process.versions,
11+
});
12+
13+
console.log('\nCommand line parameters:');
14+
process.argv.forEach((value, index) => {
15+
console.log(`${index}: ${value}`);
16+
});
17+
18+
console.log('\nEnvironment variables:');
19+
for (const name in process.env) {
20+
const value = process.env[name];
21+
console.log(`${name}: ${value}`);
22+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy