Basic knowledge of string concatenation in JavaScript

Source: Internet
Author: User

Very simply, "add" two strings with a "+":

   var longstring = "One Piece" + "plus one more piece."; 


To accumulate more than one string as a string, you can also use the "+ =" Operator:

   var result = "";


   result = "My name was Anders" result + = "and I Age is


   25"; 




To add a line break in a string, you need to use the escape character "":

   var confirmstring = "You did don't enter a response to the" "+
    " question. Submit form anyway? ";


   var confirmvalue = confirm (confirmstring);



However, this method can only be used in cases such as warning, confirmation dialog box, if this text is rendered as HTML content, it is invalid, and then replace it with "<br>":

   var htmlstring = "A. String.<br>second line of String.";


   document.write (htmlstring);


The string object also provides a method concat () that completes the same function as "+":

   String.Concat (value1, value2, ...)



But Concat () method is obviously not as "+" come intuitive simplicity.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.