number
s or string
s in addition expressions JS-0377+
operator should be both numbers or both strings21 const app = fastify(fastifyOptions);
22
23 // Logger middleware for fastify instance (logs to console)
24 logger.info("\n\nEnvironment details: " + consoleOutput);25
26 routes(app);
27
It is recommended to use operands of the same type while adding values as mismatched operand types might result in unexpected output.
When doing addition with operands of different types, the output sometimes results in simple concatenation instead of addition.
1 + '2'
While the user may expect this to result in 3
(by integer addition) it will instead result in '12'
(by string concatenation) .
var foo = '5.5' + 5;
var foo = 1n + 1;
var foo = parseInt('5.5', 10) + 10;
var foo = 1n + 1n;