2

This looks like some sort of string.Format in JavaScript.

var some_var = "Alice",
    other_var = "Bob";
var test = `${"Hello " + some_var + ". How is " + other_var + "?"}`;
console.log(test);

What is it called? Browser compatibility?

Doubt from this question: How to pass properties to a variable function in javascript?

6
  • 1
    it's a template literal. but a bit mixed up. Commented Jul 7, 2016 at 18:14
  • 2
    Possible duplicate of What is the usage of the backtick symbol () in JavaScript?` Commented Jul 7, 2016 at 18:14
  • 1
    Use it like this: ` Hello ${some_var}. How is ${other_var}?`` ; Commented Jul 7, 2016 at 18:17
  • @h2ooooooo: I wasnt sure whats the name of that. hence cannot google. also called grave accent right? Commented Jul 7, 2016 at 18:17
  • @webdeb: Thanks. Thats much simpler. Commented Jul 7, 2016 at 18:19

2 Answers 2

2

Those are called "Template Literals".

They're part of the ECMAScript 2015 Specification.

Sign up to request clarification or add additional context in comments.

Comments

2

It's a template literal: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals

It's an ES6 feature that's now starting to get support in several js engines.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.