Ex10, what happens after changing `process.argv[2]` to `process.argv[0]`

As the image shown, the terminal spit Mojibake out after changing process.argv[2] to process.argv[0].
Can you tell me what happen?

Hi @gantrol process.argv[2] takes as the third argument the input-file ‘test.txt’. The second argument process.argv[1] is the code-file ‘ex10.js’ and the first argument process.argv[0] is the ‘node’ program. So what you get is the binary code of the compiled node-program!

process.argv[0]  |  process.argv[1]  |  process.argv[2]
node             |  ex10.js          |  test.txt

Thanks~May you tell me why I can the binary code by this way?

Because it’s just a file inside your computer. If you call it with process.argv[0] it tries to read it.

1 Like

Hey @gantrol, you actually hit a cool feature of computers. Code is data and data is code. Your node program is just a file on the computer and that makes it data but you feed that data to a CPU and it’s code.

2 Likes
A free service run by Zed A. Shaw for learncodethehardway.org.