number
s or string
s in addition expressions JS-0377+
operator should be both numbers or both strings 8
9 const i = Math.floor(Math.log(bytes) / Math.log(k));
10
11 return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + " " + sizes[i];12}
13
14export default FormatBytes;
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;