node script.js hello world. What will it print?console.log(process.argv.slice(2));The process.argv array contains the node executable path at index 0 and the script path at index 1. Using slice(2) returns only the arguments passed after the script name, which are "hello" and "world".
node app.js --name=John --age=30, what is the value of args?const args = process.argv.slice(2);
console.log(args);The process.argv array includes the arguments as strings exactly as typed. Since the arguments are passed as --name=John and --age=30, slicing from index 2 returns those exact strings.
node index.js a b c d, which code correctly assigns the third argument to variable thirdArg?The process.argv array contains the node executable path at index 0 and the script path at index 1. Arguments start at index 2: 'a' (2), 'b' (3), 'c' (4), 'd' (5). The third argument is 'c' at index 4.
Option B gets the first argument ('a' at index 2).
Option B returns an array from index 3 onward (['b', 'c', 'd']).
Option B: process.argv[4] gets the third argument ('c').
Option B gets the fourth element of the sliced array starting at 2, which is 'd' (index 5 overall).
node app.js test, why does it print []?const args = process.argv.slice(3);
console.log(args);process.argv has at least two elements: node path and script path. Arguments start at index 2. With one argument 'test', process.argv has length 3. Using slice(3) returns elements starting at index 3, which is beyond the last element, so it returns an empty array.
node without a script?node alone (no script, no arguments), what is the length of process.argv inside the Node.js REPL?Even when no script is provided, process.argv contains the path to the node executable at index 0 and the path to the REPL script at index 1, so its length is 2.