Monday, 15 February 2010

javascript - Surprising simple operation results -



javascript - Surprising simple operation results -

in javascript, tried executing below statements

var x = 1+"2"-3; //anser 9. var y = 1-"2"+4 //anser 3.

for such operations, converted what?

i guess 1+"2" = 12(number) , 12-3?

- converts both operands numbers. if either operand + string, other converted string , it's concatenation. "hi, " + "how you?" = "hi, how you?" answers correct.

var x = 1+"2"-3; // concats string 12 , subtracts... 12 - 3 = 9 var y = 1-"2"+4 // converts numbers , subtracts, making -1 , adds 4 giving out 3 -1 + 4 = 3

this process.

javascript jquery

No comments:

Post a Comment