FIND YOUR NEXT FEW LINES

Results for “JavaScript”

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

132 snippets foundClear filters
JavaScriptPromises & iteration protocols

Use the first fulfilled promise result

JavaScript: Promise.any ignores individual rejections until one input fulfills.

JavaScript✓ Tested
JavaScriptNumbers & numeric validation

Validate a finite numeric value without coercion

JavaScript: Number.isFinite rejects numeric strings as well as NaN and infinity.

JavaScript✓ Tested
JavaScriptRegular expressions & URL encoding

Validate a whole ASCII identifier

JavaScript: Use an anchored expression without the multiline flag and reject a trailing line break explicitly.

JavaScript✓ Tested
JavaScriptGetting Started

Visit every item in a collection

JavaScript: Print each element in the collection’s original order.

JavaScript✓ Tested
JavaScriptFiles & async

Wait for multiple promises

Use Promise.all to collect JavaScript results in input order.

JavaScript✓ Tested
JavaScriptFiles & async

Write a UTF-8 file

Use the built-in Node.js filesystem API to save text.

JavaScript✓ Tested
TypeScriptUTC date operations

Convert epoch milliseconds to whole seconds

TypeScript: JavaScript Date stores milliseconds while many APIs use Unix seconds.

TypeScript✓ Tested
HTMLData & disclosure

Create a native disclosure

Use details and summary to show optional HTML content without JavaScript.

HTML✓ Tested
TypeScriptSafe data handling

Safely read a caught error

Check the error type before accessing its message.

unknown✓ Tested
HTMLNative disclosure & dialogs

Start a disclosure open while keeping it collapsible

HTML: The open attribute sets the initial details state without JavaScript.

HTML✓ Tested
jQueryForm serialization & state

Store an object associated with an element

jQuery: data retains JavaScript values without serializing them into HTML attributes.

jQuery✓ Tested
jQueryCollections & styling

Transform a collection into a plain array

jQuery: map followed by get returns ordinary JavaScript values.

jQuery✓ Tested