Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • concat() method in JavaScript String

    • 0
    • 1
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 303
    Comment on it

    JavaScript String concat() method : To join one or more strings we use the concat method in JavaScript String.


    Syntax of concat method :

    string.concat(string1, string2, ..., stringX)
    

    In the above syntax you can pass any number of parameters one or more than one.


    Example of concat method : Here I will show you how you can add single string in first example and in second example I will show you to add two strings into one string.


    Sample1.html

    <!DOCTYPE html>
    <html>
    <body>
    
    <p>We will join two strings.</p>
    <button onclick="joinString()">Join</button>
    <p id="container"></p>
    
    <script>
    function joinString() {
        var val1 = "Welcome ";
        var val2 = "User!";
        var result = val1.concat(val2);
        document.getElementById("container").innerHTML = result;
    }
    </script>
    </body>
    </html>
    
    Output : Welcome User!
    

    Sample2.html

    <!DOCTYPE html>
    <html>
    <body>
    
    <p>We will join two strings to one string.</p>
    <button onclick="joinString()">Join</button>
    <p id="container"></p>
    
    <script>
    function joinString() {
        var val = "He ";
        var val2 = "is";
        var val3 = " great person.";
        var result = val.concat(val2, val3);
        document.getElementById("container").innerHTML = result;
    }
    </script>
    </body>
    </html>
    
    Output : He is great person.
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: