question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to output variables in a string in ES6

See original GitHub issue
var myName = 'My name is ${fullname}.';
var url = 'http://mysite.com/api/user/${id}';
console.log(myName); //My name is Khalil
console.log(url); // http://mysite.com/api/user/123

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
jadjoubrancommented, Dec 16, 2017

Awesome idea, will push this today! 😄

interpolate
1reaction
khalilsarabeycommented, Dec 16, 2017

That’s cool @jadjoubran ! I didn’t check the entire list on the site 😃 I think you can take it a step further by providing an expression interpolation example like:

var calculate = '1+1 = ${ 1 + 1 }'; console.log(calculate); //1+1 = 2

Read more comments on GitHub >

github_iconTop Results From Across the Web

Getting Literal With ES6 Template Strings - Chrome Developers
As all string substitutions in Template Strings are JavaScript expressions, we can substitute a lot more than variable names.
Read more >
Template literals (Template strings) - JavaScript | MDN
Template literals are literals delimited with backtick ( ` ) characters, allowing for multi-line strings, string interpolation with embedded ...
Read more >
How to interpolate variables in strings in JavaScript, without ...
Complete and ready to be used answer for <ES6: var Strings = { create : (function() { var regexp = /{([^{]+)}/g; return function(str, ......
Read more >
ES6 Variables and Strings | Sololearn: Learn to code for FREE!
Complete the function to return a string in the. ... ES6 Variables and Strings ... Capital: Lisbon Use template literals to output variables...
Read more >
String Interpolation in JavaScript - Dmitri Pavlutin
toString() array method executes array.join(',') when the array is converted to string. Thus the string interpolation result is 'The numbers are ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found