Friday, 24 August 2018

JavaScript: String concatenation operator

+ Operator is used to concatenate strings. + operator takes two operands and concatenate them, it is not necessary that both should be of type strings to concatenate. If one of the operand is string, then Javascript converts other operand to string automatically.

concat.html
<!DOCTYPE html>

<html>

<head>
    <title>String concatenation</title>
</head>

<body>
    <script type="text/javascript">
        var a = "Hello";
        var b = "World";
        var c = 10;

        document.write("a = " + a + "<br />");
        document.write("b = " + b + "<br />");
        document.write("c = " + c + "<br />");

        document.write("a+b = " + (a + b) + "<br />");
        document.write("a+c = " + (a + c) + "<br />");
    </script>
</body>

</html>



Previous                                                 Next                                                 Home

No comments:

Post a Comment