JavaScript gah!

JavaScript bit me again, with its concatenation operator being the same as its addition operator. So instead of the total amount of an order, I ended up with a string of all the prices in the order. Grrr.

I must remember what Crockford says in Appendix A: Awful Parts:

The + operator can add or concatenate. Which one is does depends on the types of the parameters. If either operand is an empty string, it produces the other operand converted to a string. If both operands are numbers, it produces the sum. Otherwise, it converts both operands to strings and concatenates them. This complicated behaviour is a common source of bugs. If you intend + to add, make sure that both operands are numbers.
0 responses