User:Extremecircuitz~enwikibooks/Strings

What is a string?
Strings are pieces of unformatted text, and may contain html to format the appearance for the viewer. (You are the viewer of this page, and this text you are reading is made up of strings) They have many uses, from storing the value of an input field in a variable to specifying the content of a pop-up.

String variables
Strings are common in variables. When a variable has a string(s) in its value, the string(s) are enclosed within quotation marks.

Example: var string = "This is a string"; document.write(string); Displays: This is a string

Sometimes, however, a variable contains other variables along with strings. In this case, the variables are outside the string closing/opening quotations, with a plus (+) sign on either side. Example: var othervar = "variable"; var string  = "This is a " + othervar + " within another " + othervar + " as a string"; document.write(string); Result: This is a variable within another variable as a string

In the case of html-content string variables, sometimes the "+=" assignment is used. What this does in the case of strings is adds to what is already in the variable. Example: var string; string = ""; string += "This "; string += "is "; string += "a "; string += "string "; string += "using "; string += "the "; string += "\"+=\" "; string += "assignment."; document.write(string); Returns This is a string using the "+=" assignment