Articles by Olorunfemi Akinlua
JavaScript check if string contains space or whitespace (indexOf, RegExp, trim)
Check if a string contains spaces in JavaScript: literal U+0020 vs Unicode whitespace, indexOf and includes, RegExp \s, trim for ends-only emptiness, and NBSP (U+00A0) pitfalls. Runnable Node snippets with short …
JavaScript double exclamation mark (!!): boolean coercion
JavaScript double exclamation (!!) vs Boolean(): same boolean coercion to true/false, truthy and falsy lists, TypeScript idiom, and why [] is truthy. Runnable Node snippets with short output notes.
JavaScript double question mark (??): nullish coalescing
JavaScript double question mark (??) is nullish coalescing: defaults only for null or undefined, unlike ||. Covers chaining, mixing with ||/&& (parentheses), and examples where 0 and empty string must be preserved. …
JavaScript findIndex: array findIndex and objects by property
findIndex javascript and js findIndex: predicate scan with Array.prototype.findIndex, return index or -1, optional thisArg, javascript find index of object in array by property, and how findIndex differs from find and …
Compare strings in JavaScript: ===, localeCompare, and case-insensitive matches
JavaScript string compare and string equals with === vs ==, localeCompare and Intl.Collator for locale-aware sorting, case-insensitive patterns, trim and Unicode normalize—with example console output.
Convert an array to a string in JavaScript (join, toString, JSON)
Convert array to string in JavaScript with join, toString, String(), toLocaleString, JSON.stringify, reduce, or loops—with example output and common pitfalls (objects, BigInt, null/undefined).
JavaScript appendChild() — add and move DOM nodes
Use Node.appendChild in JavaScript to add or move elements. Includes append vs appendChild, DocumentFragment batching, insertBefore, cloneNode, and jsdom-tested console output.
Convert SRT subtitles to plain text in JavaScript with regex
Convert srt to text or srt to txt in JavaScript: regex to remove index and timestamp lines, line-skip variant, block split for multi-line cues, Node readFileSync/writeFileSync with utf8—no npm install fs. Includes …
JavaScript date formatting with Intl.DateTimeFormat
Format dates in JavaScript with Intl.DateTimeFormat: locales, dateStyle and timeStyle, time zones, formatRange, formatToParts, and common TypeErrors. Includes tested sample output from Node.js (V8).
Parse a string to a boolean in JavaScript
Coerce strings with Boolean() and !!, or parse canonical values like 'true'/'false'. Learn the difference and avoid common mistakes.
Calling vs invoking functions in JavaScript: what actually happens to this
Call vs invoke and invoke vs call in JavaScript: both usually mean run a function. Clarify this binding, method calls vs free calls, Function.prototype.call naming, and library methods named invoke—with example console …
Detect ad blockers in JavaScript: bait DOM, heuristics, and what not to break
How to detect adblock in JavaScript: bait DOM patterns, getComputedStyle and offsetWidth checks, BlockAdBlock (blockadblock js) global guard, common API mistakes, limitations and false positives—with example branch logic …
Clear timeouts in JavaScript: clearTimeout and patterns that scale
Use clearTimeout (cleartimeout in search terms) to cancel one or many setTimeout timers. JavaScript has no built-in clear-all—track handles in a Set or array, including in Node.js. Includes Node-tested console output, …
JavaScript Exponentiation: ** Operator vs Math.pow (BigInt, precedence, edge cases)
Exponentiation in JavaScript with the ** power operator and Math.pow: numbers, BigInt, right-associativity, unary minus precedence, NaN ** 0, **= compound assignment, and when to prefer Math.pow on older engines. Each …
JavaScript await: async functions, try/catch, Promise.all, top-level await
How await works in JavaScript: javascript await, js await, async await javascript, await promise inside async functions, sequential vs Promise.all concurrency, try/catch on rejections, await on non-promises, top level …
JavaScript factory pattern (functions, classes, and async factories)
JavaScript factory pattern and factory functions: return plain objects, pick implementations by input, constructor-based factories, ES6 class factories, closure privacy, and async factories—with Node-tested output.
Error: cannot find module express
Error: Cannot find module 'express' This error is quite common and exists because when your code ran, the express package or module wasn’t found within its environment.
Error: Cannot find module X in JavaScript
We can solve Error: Cannot find module by installing the missing module. We can use npm tool to install the mising module.
How to add items to array in Node.js
We can use 3 different methods to add items to array in Node.JS using push, unshift or concat method
Wait For Loop to Finish in Node.js
We can use promise.all to check and wait for loop to finish in Node.js
Update key with new value in JavaScript
We can either use foreach loop of maps function to update key with new value in Javascript
How to sort a map by value in JavaScript?
Different methods to sort map by value in javascript (JS) in both ascending and descending order.
println JS alternative available?
The alternative of java println in javascript is console.log()
