JavaScript & jQuery Tutorials

JS Home Right Arrow JS Reference Right Arrow String

String operators

String concatenator.

Description

Concatenates string values together using the concatenation operator (+) or the shorthand assignment operator (+=).

  • Strings are created using the global object constructor new String() or created as string primitives.
  • String literals are string primitives and are created by enclosing some value in single or double quotes.

String Concatenation

There are a few things to remember when concatenating strings together:

  • In JavaScript we use the + symbol to join two or more strings together.
  • The JavaScript intepreter uses automatic type conversion when combinining string and numbers, which means all numbers are converted to strings before concatenation takes place.

Examples

The following code should shed light on the above.


// Create a string and numeric variables.
var aString = '5';
var aNumber = 5;
// Concatenation ends up with a string holding the value  '55' not 10.
alert(aString + aNumber);

Press the button below to action the above code:

Related Tutorials

JavaScript Basic Tutorials - Lesson 8 - Strings



  

go to home page Homepage go to top of page Top