Benefits of JavaScript Template Literals

Asked 1 years ago, Updated 1 years ago, 318 views

Use "+" to concatenate strings

console.log("Name is "+name+"")

but not the template literal

console.log(`name is ${name})`)

Are the benefits of using only improved visibility?

Whenever I do string concatenation, I always wonder which one to use.

javascript ecmascript-6

2022-09-30 22:00

2 Answers

I think it's good to use the template literal only to improve visibility.
ESLint's fix option also provides automatic conversion.

https://eslint.org/docs/rules/prefer-template


2022-09-30 22:00

One advantage is that " or ' appear in the string, but no escape is required.On the other hand, ` needs to be escaped, but it's not something I use that much.


2022-09-30 22:00

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.