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: coursesweb.net";     // with double quotes
// or
var variable_name1 = 'some text: coursesweb.net';     // 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 = "CoursesWeb.net "JS lesson"";     // SyntaxError: missing ; before statement

// Correct
var a_name = "CoursesWeb.net \"JS lesson\"";
// or
var a_name = 'CoursesWeb.net "JS lesson"';
// or
var a_name = "CoursesWeb.net 'JS lesson'";
--></script>

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

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, "");
            }

JavaScript Strings

Daily Test with Code Example

HTML
CSS
JavaScript
PHP-MySQL
Which tag is a block element?
<div> <img> <span>
<div>Web Programming and Development</div>
Which CSS code displays the text underlined?
font-style: italic; text-decoration: underline; font-weight: 500;
h2 {
  text-decoration: underline;
}
Click on the JavaScript function that can access other function after a specified time.
insertBefore() setTimeout() querySelector()
function someFunction() { alert("CoursesWeb.net"); }
setTimeout("someFunction()", 2000);
Click on the instruction that returns the number of items of a multidimensional array in PHP.
count($array) count($array, 1) strlen()
$food = array("fruits" => array("banana", "apple"), "veggie" => array("collard", "pea"));
$nr_food = count($food, 1);
echo $nr_food;       // 6

Last accessed pages

  1. PHP-MySQL free course, online tutorials PHP MySQL code (28365)
  2. PHP MySQL Introduction, Data Types (2073)
  3. Insert, Select and Update NULL value in MySQL (8083)
  4. Dibblez Apple Hunt (15)
  5. AJAX and Forms (785)

Top accessed pages

  1. Courses Web: PHP-MySQL JavaScript Ajax HTML CSS Flash-AS3 (35437)
  2. PHP-MySQL free course, online tutorials PHP MySQL code (28365)
  3. Read Excel file data in PHP - PhpExcelReader (27181)
  4. Get Attribute (ID, Class, Name, Title, Src) with jQuery (26532)
  5. PHP PDO - exec (INSERT, UPDATE, DELETE) MySQL (23273)