|
1. What's the value of the following expressions?
a) 1+ 2+ " buckle my shoe"
b) "one-"+ "two"+ " buckle my shoe"
c) ""+ 1+ 2+ " buckle my shoe"
d) '1'+ 2+ " buckle my shoe"
e) 1+ "-2"+ " buckle my shoe"
3 buckle my shoe -- one and two are added
together and concatenated to the string
one-two buckle my shoe -- the three strings
are concatenated
12 buckle my shoe -- The first string ensures
the whole line is a string thereby printing 1 and 2 instead of adding them
together.
51 buckle my shoe -- the ASCII value of char
'1' is 49 added to the integer 2 produces ASCII value 51, which is
concatenated to the trailing string.
1-2 buckle my shoe -- the integer value 1 is
concatenated to the trailing two strings.
Using the valueOf() method we come up with the above strings.
Send me email
Visit my website
|