JavaScript Tutorials - Herong's Tutorial Examples - 2.33, by Herong Yang
String Literals
This section provides descriptions on string literals and a tutorial example on how to use them in JavaScript source code.
To provide values of strings in JavaScript source code, you need to use string value literals following these rules:
1. String literals are sequences of Unicode characters.
2. String literals must be enclosed in single quotes ('...') or double quotes ("...").
3. Several characters must be preceded with the escaping character, backslash (\): \b, \f, \n, \r, \t, \v, \', \", and \\.
4. Latin-1 characters can be presented as hexadecimal escape sequences. For example, \xA9 represents the copyright symbol.
5. Unicode characters can be presented as Unicode escape sequences. For example, \u4E16 represents a Chinese character.
Here is a JavaScript tutorial example that shows you how to use string literals in JavaScript source code:
<html> <!-- String_Literals.html Copyright (c) 2002 HerongYang.com. All Rights Reserved. --> <head><title>String Literals</title></head> <body> <pre> <script type="text/javascript"> document.write("Hello World!"); document.write('\n'); document.write('Herong\'s Tutorial'); document.write('\n'); document.write("Double quote (\")"); document.write('\n'); document.write("Copyright \xA9 2020."); document.write('\n'); document.write("\u4E16\u754C\u4F60\u597D\uFF01"); document.write('\n'); </script> </pre> </body> </html>
The output of this sample JavaScript is:
Hello World!
Herong's Tutorial
Double quote (")
Copyright © 2020.
世界你好!
Table of Contents
ECMAScript Language Specification and JavaScript Dialects
►Data Types, Variables and Expressions
Primitive Data Types - Numbers, Strings, and Booleans
Declaring Variables - "var" Statements
Operators and Expressions - Examples
Creating, Accessing, and Manipulating Arrays
Defining and Calling Functions
Web Browser Supporting JavaScript
Server-Side and Client-Side Web Scripting
Defining Your Own Object Types
Inheritance of Properties and Methods through the Prototype Object Chain
'jrunscript' - JavaScript Shell Command from JDK
Using Functions as "Function" Objects
Introduction to Built-in Object Types
W3C's Document Object Model (DOM) Specifications