DEV Community

5 Ways to Convert a Value to String in JavaScript

Samantha Ming on May 27, 2019

If you're following the Airbnb's Style Guide, the preferred way is using "String()" πŸ‘ It's also the one I use because it's the most explicit - m...
Collapse
 
sunnysingh profile image
Sunny Singh

Thanks for sharing these comparisons. I commonly use toString(), but it makes way more sense to handle null scenarios with String(). Loves your posts (including the IG ones) as always Samantha!

Collapse
 
samanthaming profile image
Samantha Ming

Thanks for your support Sunny πŸ˜ŠπŸ‘

Collapse
 
jammypiece profile image
Lorna

Wow. It never occurred to me that different ways could have knock on effects. I'm just starting out so I wasn't even aware of String(). I'll try it. Thanks.

Collapse
 
samanthaming profile image
Samantha Ming

Yup give it a try! That’s always my default πŸ˜„πŸ’―

Collapse
 
caleb_mcquaid profile image
Caleb McQuaid

This was great! Thank you!

Collapse
 
samanthaming profile image
Samantha Ming

Awesome! Glad you found it helpful πŸ˜„πŸ‘

Collapse
 
localhost4484 profile image
Ohm

Thanks

Collapse
 
samanthaming profile image
Samantha Ming

No problem! Thanks for reading 😊