Converting to a number and string that way is risky, because you're using implicit conversions.
Instead, you can convert a number to a string by using string interpolation:
const stringNumber = `${number}`
Converting to a number can be done two ways - you can use Number or parseInt, depending on the behaviour you need when it's not quite a number:
Number
parseInt
const numberString = Number('20') // 20 const numberWang = parseInt('20 cows') // 20
True! I was trying to find other ways to do the conversations. These are the better options clearly.
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Converting to a number and string that way is risky, because you're using implicit conversions.
Instead, you can convert a number to a string by using string interpolation:
Converting to a number can be done two ways - you can use
Number
orparseInt
, depending on the behaviour you need when it's not quite a number:True! I was trying to find other ways to do the conversations. These are the better options clearly.