Skip to content

Instantly share code, notes, and snippets.

@darcher-
Last active October 10, 2023 17:26
Show Gist options
  • Save darcher-/1568fa33b20c373d75d74766ab481f11 to your computer and use it in GitHub Desktop.
Save darcher-/1568fa33b20c373d75d74766ab481f11 to your computer and use it in GitHub Desktop.
a look back at the evolution of string "merging" in javascript
/** EXAMPLE */
//? start
//* legacy
var prefix = 'x'
var infix = 'y'
/** suffix argument */
var affix = 'id="';
affix += prefix + '-';
affix += infix + '-';
if (suffix !== null && typeof suffix !== 'undefined')
affix += newSuffix();
else
affix += 'z';
affix += '"';
//* outdated
var prefix = 'x'
var infix = 'y'
/** suffix param */
suffix = !Boolean(suffix) ? newSuffix() : 'z';
let affix = prefix + '-' + infix + '-' + suffix;
affix = 'id="' + affix + '"';
//* depreciated
const prefix = 'x'
const infix = 'y'
/** suffix arg */
const affix = `id="${[
prefix,
infix,
suffix || newSuffix() || 'z'
].join('-')}"`;
//* modern
const prefix = 'x'
const infix = 'y'
/** suffix prop (defaults to "z") */
const affix = `id="${prefix}-${infix}-${
suffix ??= newSuffix()
}"`;
// -> String(id="x-y-z")
//! end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment