Questions tagged [template-literals]

Template literals are JavaScript string literals which allow embedded expressions. They allow for multi-line strings and string interpolation. In previous ECMAScript specifications, they were called "template strings".

547 questions
11
votes
2 answers

template literals in jsx

I want to use this but props
which should give
roberto
  • 165
  • 1
  • 2
  • 8
10
votes
3 answers

Are JavaScript template literals guaranteed to call toString()?

const num = 42 const str = `My number is ${num}` In this code what guarantee do I have about the conversion of num to a string ? Is it guaranteed to just call its toString() method or could the conversion be done in another way ?
Drax
  • 12,682
  • 7
  • 45
  • 85
10
votes
2 answers

How to call calling a function inside a Template literal

How can I go about calling a function inside a Template literal. The function syntax in the attempt below shows in the HTML: function readURL(input) { if (input.files && input.files[0]) { var reader = new FileReader(); var html…
Program-Me-Rev
  • 6,184
  • 18
  • 58
  • 142
9
votes
1 answer

Is it possible to generate string literal combinations with template literal in TypeScript?

Is it possible to generate permutation of combinations of string literal with template literal in TypeScript? type MetaKey = 'meta'; type CtrlKey = 'ctrl'; type ShiftKey = 'shift'; type AltKey = 'alt'; type ModiferKeyCombinations = ??? where…
aztack
  • 4,376
  • 5
  • 32
  • 50
9
votes
2 answers

Why can't String.raw end with a backslash?

String.raw can be used to create a string that contains backslashes, without having to double up those backslashes. Historically, you'd need to double up backslashes when creating a string: let str = "C:\\Program…
Lonnie Best
  • 9,936
  • 10
  • 57
  • 97
9
votes
4 answers

How would you turn a JavaScript variable into a Template literal?

I would like to take text that I generated and stored in a string and use it like a template literal. var generatedText = "Pretend this text was generated and then stored in a variable. "; generatedText = "But I still need to use it as a template…
Trevor
  • 139
  • 1
  • 7
9
votes
3 answers

Setting HTML Button`onclick` in template literal

I have an html template that i'm using template literals for. The function looks like the below // postCreator.js export const blogPostMaker = ({ title, content, address, id }, deletePost) => { const innerHtml = `
Elliott McNary
  • 1,149
  • 3
  • 11
  • 20
9
votes
4 answers

Text highlighting for ES6 template literals (backticks) in IntelliJ IDEA

Where should I look in the settings to remove the green background highlighting for text within the backticks? I think it is related to HTML in non-HTML files, probably it has nothing to do with quotes or backticks. I've been searching through…
8
votes
2 answers

Truly recursive Template Literal for comma-separated strings in Typescript

I am trying to define a Typescript template literal for a string containing comma-separated values. Can I make this definition truly recursive and general? See this typescript playground to experiment with the case. Each comma separated value…
cefn
  • 2,895
  • 19
  • 28
8
votes
6 answers

Ternary inside string literals

Been trying to add a conditionals inside a template strings. I am unable to do it. I have two strings say t1 and t2, and when t2 is undefined or empty just display t1 and when t2 is present append that t2 inside parentheses along with t1 let t1=…
joy08
  • 9,004
  • 8
  • 38
  • 73
8
votes
1 answer