JavaScript string tutorial

Home - Tutorials - Basics

In this tutorial you will learn how to use and manipulate strings in JavaScript.

Tutorial info:

Name:JavaScript string tutorial
Total steps:3
Product:See complete product

Bookmark JavaScript string tutorial

AddThis Social Bookmark Button

Step 1 - JavaScript string basics

JavaScript string tutorial

The string in JavaScript - similar to other programing languages - is a variable which stores a series of characters. A string can be any text inside a quote pair. You can use simple or double quotes, but of course the pairs must match. The next code example shows how you can define strings in JavaScript:

  1. var str1 = 'Test string 1';
  2. var str2 = "Test string 2";
  3. var str3 = 'It\'s a string';
  4. var str4 = "This is an 'internal' string";
  5. var str5 = 'This is also an "internal" string';

As you can see in case of str3 we used a single quote to define our string content, but the text itself also contains a single quote. In such cases you need to use a backslash character before the single quote to display your text properly.

Concatenating strings  

You can also create a string by concatenating more strings together. This could be very useful if you build up your string within an application logic. To do this you have 2 operators to use. The + and the +=. The example below shows you how to use them.

  1. var str1 = 'This ' + 'is ' + 'a ' + 'demo!';
  2. var str2 = 'Part 1';
  3. str2 += ' and Part 2';
  5. var str3 = 'Mixed ';
  6. str3 += 'mode ' + 'is possible.';

In the next section I will show you how to use the most basic string manipulation functions.

Next Step of JavaScript string tutorial

Tags: javascript string functions, javascript string, javascript, string, function

JavaScript string tutorial - Table of contents
Step 1 - JavaScript string basics
Step 2 - String manipulation with JavaScript
Step 3 - More string manipulation functions

GAD Tower

F1 Site Family
Database F1
Java F1
JavaScript F1

Family tutorials
PHP Array
PHP Redirect
PHP Session
AJAX File Upload
AJAX Rating System
MySQL Create User
Mysqldump Example
MySQL Concat

Total time: 0.1473