Skip to content

jfarmer/examples-javascript

Repository files navigation

Examples

Here are some examples of common patterns in Javascript.

Command Line Arguments

Run examples/commandLineArgs.js from the command line and read the code to get an overview of how command line arguments work.

When we run a program like:

node hello.js one two three

our program in hello.js can get access to an array that looks like

['one', 'two', 'three']

These are called "command line arguments".

Add

Run examples/add.js from the command line to see how it works. This is a "fully-featured" command line program that adds two numbers.

It contains proper error handling and useful help messages. It's heavily commented.

Random Numbers

In JavaScript, we use Math.random to generate random numbers.

Run examples/random.js from the command line and read the code for an overview of common patterns involving random numbers.

Reading From Files

Run examples/readFile.js from the command line and read the code to see examples of how to read from a file.

Interactive Keyboard Input

Run examples/keyboardInput.js from the command line and read the code to see examples of interactive keyboard input.

We're using the readline-sync module.

You'll need to run the following command inside the examples-javascript directory to install readline-sync:

npm install

Hidden Input

Run examples/password.js from the command line and read the code to see examples of how to hide user inputs.

We're using the readline-sync module.

You'll need to run the following command inside the examples-javascript directory to install readline-sync:

npm install

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published