Which string concatenation is better?

I wonder which string concatenation is "better", faster, or even both?

Option 1:

 let value = "Instance 0"; console.log('Using instance: ' + value);

Option 2 (Template literals):

 let value = "Instance 0"; console.log(`Using instance: ${value}`);

Thank you!

(1 votes)
Loading...

Similar Posts

Subscribe
Notify of
7 Answers
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
FaTech
1 year ago

It depends. You don’t need to talk about JavaScript anyway. And that’s not so much. But I’d prefer two. If you have a user, he reads it more easily than with +

FaTech
1 year ago
Reply to  Chris102004

Multiple strings? Yeah, still. Because you keep reading flow and do not have thousands of irritating plus signs

guteantwort626
1 year ago
Reply to  FaTech

You don’t need to talk about JavaScript anyway 😅

Clear, compiled languages like C/C++ are faster, but it is not as slow now.

MonkeyKing
1 year ago

But that doesn’t matter because the speed differences are so minimal that they don’t fall into weight.

jort93
1 year ago

Depends on the browser/js engine which is faster from both.

Afaik is the first faster in chrome and the second faster in Firefox.