For ES2015, you can use Template/String literals.
TIPS: you can use Babel (or use babel-loader with Webpack) for cross-browser support.
var value = 'world'var str = `Hello ${value}`
It's basically an expression, so you could include function call, etc.
function addNumber(a, b) { return a + b;}var a = 1;var b = 2;console.log(`${a} + ${b} = ${addNumber(a, b)}`);console.log(`${a} + ${b} = ${a + b}`);
Or, you can write your own String.format function.
- https://stackoverflow.com/a/18405800/561259
- https://stackoverflow.com/a/1038930/561259
- https://stackoverflow.com/a/5077091/561259
// include any of the above implementation."Hello {0}".format("world")