1st Part:
Because When you are adding two arrays, everything works as expected:
[] + [] //output:''
Adding an array and an object also conforms to our expectations:
[] + {}
output:'[object Object]'
{} + {}
in JavaScript is NaN
?
and this is unexpected result so what is the reason behind this?
2nd part:
In string comparison without prefix 0, 3 is greater than 12:
"3" > "12"
: true
With padding, everything works correctly:
"03" > "12"
: false
Is prefix 0 compulsory for string comparision?What is the reason for adding prefix 0 ?