Help
05-15-2003, 01:31 PM
what's the concatenation operator?
|
Click to See Complete Forum and Search --> : concatenation operator? Help 05-15-2003, 01:31 PM what's the concatenation operator? AdamGundry 05-15-2003, 01:35 PM + http://devedge.netscape.com/library/manuals/2000/javascript/1.3/reference/ops.html#1042582 Adam pyro 05-15-2003, 01:38 PM The concatenation operator is the +. The + adds numeric operands, but concats strings. To convert a number to a strin, use the value = number.toString() method... havik 05-15-2003, 03:23 PM example: var firstname = "John"; var lastname = "Doe"; var fullname = firstname + " " + lastname; Havik Charles 05-15-2003, 03:34 PM Originally posted by pyro To convert a number to a strin[g], use the value = number.toString() method... Or just use the number as a string, a la alert(3.14159) and '0' + 4. In fact, to convert anything to a string just use it as a string. If it's an object then JavaScript will automatically call its toString() method. Primitives work a little differently under the hood but the result is the same. And JavaScript has two other useful ways to concatenate. The document.write method will take any number of arguments and will concatenate them: document.write('fee', 'fie', 'foe', 'fum'). And the Array.join() method can be very useful: ['fee', 'fie', 'foe', 'fum'].join(', '). webdeveloper.com
Copyright Internet.com Inc., All Rights Reserved. |