最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - what is the difference between " and ` in JS? - Stack Overflow

programmeradmin0浏览0评论

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!

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!

Share Improve this question edited Jun 25, 2019 at 10:19 user330315 asked Jun 25, 2019 at 9:09 Lídia PelejàLídia Pelejà 691 silver badge5 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 5

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/en-US/docs/Web/JavaScript/Reference/Template_literals

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

发布评论

评论列表(0)

  1. 暂无评论