How to use String type in Javascript

Description

The String type represents a sequence of 16-bit Unicode characters. Strings can be created by either double quotes (") or single quotes ('). The quotes must match(start with " end with ").

Both of the following are legal:


var firstName = "first";
var lastName = 'last';

A string beginning with a double quote must end with a double quote, and a string beginning with a single quote must end with a single quote.

For example, the following will cause a syntax error:


var firstName = 'a string";    //syntax error - quotes must match

Example


var firstName = "first"; 
var lastName = 'last';
console.log(firstName);
console.log(lastName);

The code above generates the following result.





















Home »
  Javascript »
    Javascript Introduction »




Script Element
Syntax
Data Type
Operator
Statement
Array
Primitive Wrapper Types
Function
Object-Oriented
Date
DOM
JSON
Regular Expressions