JavaScript String method: concat()
[this page | pdf | back links]
The concat() method (when applied to a JavaScript
string) returns
the result of joining two or more strings together.
It
has the following syntax with the following parameters:
string.concat(string1, string2, …)
Parameter
|
Required / Optional
|
Description
|
string1, string2, …
|
Required
|
Strings to be
concatenated (joined) together
|
EXAMPLE:
HTML USED IN THIS EXAMPLE:
<!DOCTYPE html>
<html> <!-- Copyright (c) Nematrian Limited 2018 -->
<head>
<style>
table,th,tr,td {border: 1px solid black; border-collapse: collapse;}
</style>
</head>
<body>
<table>
<tr>
<th>Example</th>
<th>Resulting value of <code>x</code></th>
</tr>
<tr>
<td><code id="Example"></code></td>
<td><code id="Result"></code></td>
</tr>
</table>
<script>
var y = "abcde", z = "fg";
document.getElementById("Example").innerHTML =
'var y = "' + y + '";<br>' +
'var z ="' + z + '";<br>' +
'var x = y.concat(z);';
document.getElementById("Result").innerHTML
= y.concat(z);
</script>
</body>
</html>
|
FUNCTION THAT MAY ASSIST IN TESTING WHETHER FEATURE IS SUPPORTED:
function isSupportedJavaScriptMethodStringConcat() {
var z = "abc"; return !!z.concat;
} |
NAVIGATION LINKS
Contents | Prev | Next | JavaScript String Variables