What is the declaration of the string with "" serious underscore in javascript?

10

I was messing with the Google Chrome console these days and then, as my keyboard was unconfigured, I accidentally typed in the grave accent 'instead of the single quotation marks ' to create a string .

The interesting thing is that it worked correctly:

'teste da minha string'

What is the difference between this way of declaring the string, for the string below?

'teste da minha string'
    
asked by anonymous 10.11.2015 / 20:43

1 answer

16

In the new version of the specification (ECMAScript 6), backticks delimit templates ( template strings ), in which language is able to interpolate variables and expressions. MDN example:

var a = 5;
var b = 10;
console.log('Fifteen is ${a + b} and\nnot ${2 * a + b}.');

These templates may even contain line breaks:

var c = 'Começa aqui...
         ... e termina aqui';

Test on the Chrome console, it works! ;)

    
10.11.2015 / 20:48