|
| CONCATENATION IN JAVASCRIPT
Concatenation refers to the process of adding strings together. In javascript, strings are added together with the + sign which is referred to as the string operator.
You use this operator to add strings to variables or variables to variables.
Example: Add Strings And variables
var firstName="John";
alert("Hello" + firstName);
HelloJohn is then outputted.
Notice that there is no space between Hello and John. To add a space between these words, add a space after Hello like below (ie move the quotation mark one space right):
alert("Hello " + firstName);
Example: Add Variables And variables
var firstName="John";
var lastName="Smith";
alert(firstName + lastName);
JohnSmith is then outputted. To add a space between John and Smith, do:
alert(firstName + " " + lastName);
|
|