First must know what objects are in programming and the fundamental concepts of the object-oriented programming (OOP), becouse the string is recognized as an object in JavaScript.
JavaScript isn't a object-oriented (OO), such as C++ or Java, but is based on objects.
In the world around us the objects are, for example: a book, a car, a television ..., In JavaScript the object s are, for example: a form, a window, buttons, images, strings ...
JavaScript sees all elements of a page as objects.
An object is a collection of values called properties.
When a property is function, it’s referred to as a method.

1. String object

There is various ways to create a string: using the new keyword or with the literal form, surround characters with either single quotes (') or double quotes (").

var instance_name = new String("string value here");      // using the "new" keyword

// Literal form
var variable_name1 = "some text:";     // with double quotes
// or
var variable_name1 = 'some text:';     // with single quotes
- The most indicated way is the literal form (with quotes).
But whichever quote you use (single or double), you can’t use it again in the middle of the string because that will end the string early.
However, you can escape any character with a backslash (\) to solve this or use single primes inside double primes (and vice versa).
<script type="text/javascript"><!--
// Incorrect
var a_name = " "JS lesson"";     // SyntaxError: missing ; before statement

// Correct
var a_name = " \"JS lesson\"";
// or
var a_name = ' "JS lesson"';
// or
var a_name = " 'JS lesson'";

Strings have one built-in property, length.
<script type="text/javascript"><!--
var a_name = ' "JS tutorials"';
alert(a_name.length);          // 27

2. String Methods

The String object has a lot of methods, as shown:

Methods That Add HTML Tags

Other string object Methods

Global Functions

JavaScript didn’t include a method for trimming whitespace off the beginning and ending of a string until recently, so for most browsers you have to provide your own.
You can use the following function:
            function stringTrim(s) {
                return s.replace(/^(\s|\u00A0)+|(\s|\u00A0)+$/g, "");

Daily Test with Code Example

Which tag adds a new line into a paragraph?
<b> <br> <p>
First line ...<br>
Other line...
Which CSS property can be used to add space between letters?
text-size word-spacing letter-spacing
#id {
  letter-spacing: 2px;
What JavaScript function can be used to get access to HTML element with a specified ID?
getElementById() getElementsByTagName() createElement()
var elm = document.getElementById("theID");
var content = elm.innerHTML;
Click on the "echo" correct instruction.
echo "" echo ""; echo """;
echo "Address URL:";
JavaScript Strings

Last accessed pages

  1. CSS Course - Free lessons (7754)
  2. JavaScript trim, rtrim and ltrim (3884)
  3. Zuma Deluxe (36444)
  4. Adding sounds to buttons (1753)
  5. Recursive function to create Multi-Level Menu in JavaScript (1822)

Popular pages this month

  1. Qwop (4646)
  2. Bubbles3 (3751)
  3. Butterfly Kyodai (3119)
  4. Drag Racer V3 (3078)
  5. Zuma Deluxe (2225)