FIND YOUR NEXT FEW LINES

The snippet library.

Small, practical examples. Search by task or narrow things down below.

25 snippets foundClear filters
JavaScriptGetting Started

Name a value that stays fixed

JavaScript: Use a constant declaration or the language’s constant naming convention for a fixed limit.

JavaScript✓ Tested
JavaScriptGetting Started

Print a number with two decimal places

JavaScript: Format a small decimal value consistently for display.

JavaScript✓ Tested
JavaScriptGetting Started

Read one character from ASCII text

JavaScript: Use a valid zero-based index to read the first character.

JavaScript✓ Tested
JavaScriptGetting Started

Read the beginning of a text value

JavaScript: Extract or display the first three ASCII characters from a known nonempty string.

JavaScript✓ Tested
JavaScriptGetting Started

Read the first collection element

JavaScript: Access index zero only after establishing that the collection is nonempty.

JavaScript✓ Tested
JavaScriptGetting Started

Repeat a fixed number of times

JavaScript: Use a counted loop to print three numbered steps.

JavaScript✓ Tested
JavaScriptGetting Started

Repeat while a condition holds

JavaScript: Count down while a positive number remains, updating the loop variable on each iteration.

JavaScript✓ Tested
JavaScriptGetting Started

Replace one collection element

JavaScript: Update an existing element at a known valid index.

JavaScript✓ Tested
JavaScriptGetting Started

Require two conditions to be true

JavaScript: Combine a lower and an upper bound to check whether a value is in range.

JavaScript✓ Tested
JavaScriptGetting Started

Run your first program

JavaScript: Start with a complete program that prints one line. Follow the run instructions below.

JavaScript✓ Tested
JavaScriptGetting Started

Store a value in a named variable

JavaScript: Give a value a descriptive name and print it.

JavaScript✓ Tested
JavaScriptGetting Started

Update a running count

JavaScript: Change a variable after its initial value has been assigned.

JavaScript✓ Tested