How to accept or deny JavaScript confirmation dialogs in Capybara/Selenium

JavaScript confirmation dialogs in Capybara/Selenium can block tests or auto-dismiss unexpectedly. Direct alert handling restores accept, dismiss, and text access.

Capybara will not find links without an href attribute

JavaScript-heavy apps can render anchor tags that look clickable but lack href, so Capybara and assistive technology miss them. Adding href="#" makes link lookup and clicking work.

Shorthand function properties in ES6

ES6 object literals support concise method syntax and inline getters, replacing verbose function properties and Object.defineProperty() for simple computed values.

Using CSS transitions

Browser-native animations smooth UI state changes without JavaScript, with short durations and careful easing to avoid sluggish hover effects.

JavaScript: Humanizing durations

Format durations into the nearest human-readable unit with locale-aware pluralization using Intl.NumberFormat, defaulting to German.

Operators "in" and "of" are very inconsistent between CoffeeScript and JavaScript

in and of mean different things in CoffeeScript and JavaScript, making property checks and iteration easy to mix up.

How to set up database_cleaner for Rails with Cucumber and RSpec

Reliable test isolation for Rails with Cucumber and RSpec requires cleaning the test database up front and switching strategies for JavaScript-driven examples.

JavaScript: Testing whether the browser is online or offline

Browser connectivity can be misleading: navigator.onLine often stays true without usable internet. A real fetch with timeout can confirm whether requests actually work.

How to detect how a page was loaded in JavaScript

Navigation timing can reveal whether a document was opened, reloaded, restored from history, or prerendered. Single-page apps keep the same navigation type after client-side route changes.

Setting expiry dates for images, JavaScript and CSS

Static asset caching in Rails can be unreliable across browsers; setting expiry headers in Apache or Nginx improves delivery of images, JavaScript and CSS.

Unpoly: Loading large libraries on-demand

Large JavaScript libraries can be loaded only when needed to keep initial bundles small and avoid duplicate script execution, memory leaks, and repeated event handlers.

Matching line feeds with regular expressions works differently in every language

Dot matching for line breaks differs across regex engines, and the same modifier letters can mean different things. Ruby, JavaScript, and Perl use different patterns for matching any character.

JavaScript: Detecting the end of native smooth scrolling

Native smooth scrolling has no built-in completion signal; scrollTo() and scrollIntoView({ behavior: 'smooth' }) do not return promises, so a scroll idle timeout can wait for the animation to finish.

Use -webkit-line-clamp to natively truncate long (multi-line) texts with an ellipsis

Native CSS truncation for multi-line text adds an ellipsis after a fixed number of lines, avoiding JavaScript clamping and its performance cost.

tesseract.js: Pure Javascript OCR for 62 Languages

Browser-based OCR for scanned documents and images, with Web Worker processing and support for many input sources. Accuracy drops on distorted pages, mixed content, and layouts with tight borders.

Webpacker: Configuring browser compatibility

Browser support in Webpacker depends on both Babel and UglifyJS; mismatched settings can break legacy browsers like IE11 even when JavaScript is transpiled.

JavaScript: Calling a function with a variable number of arguments

Passing an array as separate arguments avoids treating the whole array as a single value; ES6 ... and ES5 apply spread elements into a function call.

Migrating from CoffeeScript to ES6

Moving from CoffeeScript to ES6 is straightforward with decaffeinate, which converts .coffee files to modern JavaScript and may need manual cleanup afterward.

How to read the current breakpoint tier(s) in JavaScript

Read the active viewport size in JavaScript by exposing a CSS custom property from media queries and retrieving it with getComputedStyle for responsive behavior.

Simple debounce in vanilla JavaScript

Delays repeated function calls until activity stops, reducing work from noisy events like scrolling and improving performance.

JavaScript has a native event emitter

Publish/subscribe in frontend JavaScript does not require a separate library; EventTarget provides native event listeners and dispatching for custom events.

Five years of "Today I Learned" from Josh Branchaud

A curated set of 900+ personal programming tips spans Ruby, Rails, Git, Unix, Chrome, and JavaScript, with many small shortcuts for daily development work.

JavaScript: Moving elements inside an array, modifying the array in place

Reordering an array element in place is awkward in JavaScript; splice-based helpers move items by offset and ignore out-of-bounds shifts.

JavaScript: Listening to a class getting added

Detecting when a CSS class is added can be done with a MutationObserver, useful for reacting to DOM state changes on selected elements.