DEV Community

Discussion on: Coercion in JavaScript

edisonpappi profile image
Edison Augusthy

simplest way to convert a string to a number just add + in front of the string eg: +"3"

godcrampy profile image
Sahil Bondre Author

Yea, "+" followed by any data type coerces it into Number data type. Also, using "-" followed by the data type coerces it to the negative of the Number. Point to note is that this does'nt work with other operators like *, /, %.

Thank you for letting me know about this feature! Learnt something new today πŸ˜„.