Concatenation of strings
In JavaScript strings are enclosed in "quotation
marks" and you can concatenate two strings with a plus sign a plus
sign. Here is a simple example of some JavaScript that demonstrates the
concatenation of strings
<body>
<script type="text/javascript">
<!-- My code starts here!!!
document.write("This is how you " + "concatenate strings")
//-->
</script>
</body> the above script gives you the following sentence.
This is how you concatenate strings
You can do the same thing with numbers, so to make the number 55 you can write a code like this<body>
<script type="text/javascript">
<!--
document.write("5 " + "5")
//--> </script>
(Note this example demonstrates a concatenation of a string data type)
You can also concatenate different data types, like numbers. For Example, here is
the code (the parseInt command converts strings to numbers)
<script type="text/javascript">
document.write(parseInt("5") + parseInt("5")) </script>
that gives you
Now try substituting my code and try your own concatenation
JavaScript.
|