toString or +”" to cast a number to string

in another post i talked about an “automatic” conversion of a number to string when concatenating a string in javascript.

some developers use this feature to cast a number to string.

var number = 897;
var numberToString = number + "";
> "897" #between quotes in a debug tool showing that it's a string

i don’t like this approach even considering the result is the same. the javascript has the method toString. i prefer to use this method instead of using +”".

var number = 897;
var numberToString = number.toString();
> "897" #between quotes in a debug tool showing that it's a string

the reason i prefer the method toString instead of  + “” is the readability. the concatenation with a empty string “” can be confused or misleading when another developer is reading the code. this concatenation doesn’t show clearly that its aim is cast a number to string. i believe the method toString shows clearly this aim for the developers reading this code.

dave thomas explaining what he thinks to be a clean code in the first chapter of Clean Code book says:

“Clean code can be read, and enhanced by a developer other than its original author…”