r/javascript • • Sep 18 '22

New Strings Method in ES6 JavaScript

https://techynidhi.hashnode.dev/new-strings-method-in-es6-javascript
0 Upvotes

17 comments sorted by

View all comments

8

u/yo-chill Sep 18 '22

Why use

 `${name}`.method()

Instead of just

 name.method()

6

u/xroalx Sep 18 '22

Well, using template literal will convert name to string if it isn't already, which might be useful in certain cases, but if we know it's a string already there's really no point at all.

2

u/senocular Sep 19 '22

Unless it's a symbol. String(name) would be safer.