Chapter 12. Strings, Math, and Dates

IN THIS CHAPTER

  • How to modify strings with common string methods

  • When and how to use the Math object

  • How to use the Date object

For most of the lessons in the tutorial so far, the objects at the center of attention belong to the document object model (DOM). But, as indicated in Chapter 2, "Developing a Scripting Strategy," a clear dividing line exists between the DOM and the JavaScript language. The language has some of its own objects that are independent of the DOM. These objects are defined such that if a vendor wished to implement JavaScript as the programming language for an entirely different kind of product, the language would still use these core facilities for handling text, advanced math (beyond simple arithmetic), and dates. You can find formal specifications of these objects in the ECMA-262 recommendation.

Core Language Objects

It is often difficult for newcomers to programming—or even experienced programmers who have not worked with object-oriented languages before—to think about objects, especially when objects are attributed to things that don't seem to have a physical presence. For example, it doesn't require lengthy study to grasp the notion that a button on a page is an object. It has several physical properties that make perfect sense. But what about a string of characters? As you learn in this chapter, in an object-based environment such as JavaScript, "everything that moves" is treated as an object—each piece of data from a Boolean ...

Get JavaScript® Bible, Seventh Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.