Javascript
Getting Started with Deno — Hands On

Command Line Arguments

PRO
Outline

Command line arguments allow you to write a script that can be used in many different situations without having to change the actual script. Command line arguments are passed after the path to the file. Any number of them can be passed, and they can be accessed off the Deno namespace object and the args array on that object, like this:

// command-line-arguments.ts

console.log(Deno.args[0]);

That will print out the first command line argument. The second argument is accessed with at index 1, and so on. Here's how to pass the command line argument when running the script:

deno run command-line-arguments.ts arg1 arg2

arg1 is the first command line argument, and arg2 is the second.

For this assignment, log another "Hello, world" message to the console, but this time accept and print out a command line argument.

 

I finished! On to the next chapter