Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is the difference between " and ` in JS?

this is quite an easy question but is not obvious to me.

What is the difference between this:

function fesElsDeures(subject){ 
console.log(`just started doing my ${subject} `);
}

and this:

function fesElsDeures(subject){ 
console.log("just started doing my ${subject} ");
}

It seems that in the second option, my console does not recognise the subject as a different value.

Thanks!

like image 452
Lídia Pelejà Avatar asked Sep 03 '25 01:09

Lídia Pelejà


2 Answers

Double quotes or single qoutes are just indicating string. But in first example there are not single quotes. It's a back-tick (` `) and it allows you to use embedded expression( in this case 'subject' parameter of your function).

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals

like image 151
Eli.Ez Avatar answered Sep 04 '25 14:09

Eli.Ez


Don't to be confuse with ' (Single quote) with ` (back-tick).

  • " is Double quotes,
  • ' is single quotes
  • ` is back-tick.

when you use back-tick, it allows you write multi line texts. Template literals

like image 27
Anis Mulla Avatar answered Sep 04 '25 15:09

Anis Mulla