Reading Command-Line Arguments
In the welcome video, the JavaScript port of Dev’s first lines printed the path of digest.js
and NaN, with no error. In this lesson, you found out why, and read Dev’s arguments the
JavaScript way.
Dev’s Python is trimmed to its argument lines: the week’s log is sys.argv[1] and the limit
sys.argv[2], and any reading over the limit gets flagged. A line-by-line port swaps sys.argv
for process.argv, a global, and keeps the same indexes. float() becomes Number(), which also
turns a string into a number:
const path = process.argv[1];
const threshold = Number(process.argv[2]);
console.log(`Checking ${path} against ${threshold}`);
Run with Dev’s arguments, it prints the welcome video’s line again, with no error: