this is my priority list of some of tools mentioned by him:
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
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…”
probably you know that numbers are converted to string when it’s being concatenated to a string. it’s a interesting feature. however, it’s important to have a good understanding about how this conversation works. So, unexpected results can be avoided.
the conversation occurs only when the first string is added. So,
'6' + 7 + 8 > 678
6 + 7 + '8' > 138
it’s also important to know that it doesn’t happen with other math operations, such as:
'6' + 3*3 + '7' > 697
'6' + 3-3 + '7' > 607
"6" + 7 + 8
6 + 7 + "8"
if you want, you can add you answer as a comment. or send me a tweet. i’m going to post the answer in few days.