From the workbench

Javascript

Nine standalone examples of JavaScript loops, arrays, functions, and strings. Each file prints its example result to the terminal; there are no dependencies or build tools.

View source on GitHub
  • JavaScript

From the repository

Read on GitHub

JavaScript exercises

Nine standalone examples of JavaScript loops, arrays, functions, and strings. Each file prints its example result to the terminal; there are no dependencies or build tools.

Run

Install Node.js, then run an individual example from this directory:

node J2.js

Expected output: 10.

Exercise map

FileConceptExample result
J1.jsfor loopNumbers 1 through 10, one per line
J2.jsSum an array10
J3.jsFind the largest array member9
J4.jsEven/odd classificationEven, then Odd
J5.jsReverse a stringolleh
J6.jsMerge arrays using spread[1, 2, 3, 4]
J7.jsFilter even numbers[2, 4, 6]
J8.jsTemplate literalHello Alice, welcome!
J9.jsArrow functionHello, Alice

Console spacing for arrays depends on Node.js. Change the inputs at the bottom of each file to experiment. findLargest assumes a nonempty array; reverseString reverses UTF-16 code units rather than user-perceived Unicode characters. No automated test suite is included.

More documentation

Source reference · Verification and operations