O'Reilly logo

JavaScript® Bible, Seventh Edition by Paul Novitski, Danny Goodman, Tia Gustaff Rayl, Michael Morrison

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 15. The String Object

IN THIS CHAPTER

  • How to parse and work with text

  • Performing search-and-replace operations

  • Scripted alternatives to text formatting

The tutorial in Chapter 8, "Programming Fundamentals, Part I," introduced you to the concepts of values and the types of values that JavaScript works with—features such as strings, numbers, and Boolean values. Chapter 12, "Strings, Math, and Dates," described several characteristics and methods of strings. In this chapter, you look more closely at the very important String data type, as well as its relationship to the Number data type. Along the way, you encounter the many ways in which JavaScript enables scripters to manipulate strings.

Note

Much of the syntax that you see in this chapter is identical to that of the Java programming language. Because the scope of JavaScript activity is much narrower than that of Java, you don't have nearly as much to learn for JavaScript as you do for Java.

String and Number Data Types

Although JavaScript is what is known as a "loosely typed" language, you still need to be aware of several data types, because of their impact on the way you work with the information in those forms. In this section, we focus on strings and two types of numbers.

Simple strings

A string consists of one or more standard text characters placed between matching quote marks. JavaScript is forgiving in one regard: You can use single or double quotes, as long as you match two single quotes or two double quotes around a string. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required