Skip to Content
JavaScript: The Missing Manual
book

JavaScript: The Missing Manual

by David Sawyer McFarland
July 2008
Beginner
543 pages
17h 59m
English
O'Reilly Media, Inc.
Content preview from JavaScript: The Missing Manual

Chapter 4. Working with Words, Numbers, and Dates

Storing information in a variable or an array is just the first step in effectively using data in your programs. As you read in the last chapter, you can use data to make decisions in a program (“Is the score 0?”). You’ll also frequently manipulate data by either searching through it (trying to find a particular word in a sentence, for example), manipulating it (rounding a number to a nearest integer), or reformatting it to display properly (formatting a number like 430 to appear in the proper monetary format, like $430.00).

This chapter will show you how to accomplish common tasks when working with strings and numbers. In addition, it’ll introduce the JavaScript Date object, which lets you determine the current date and time on a visitor’s computer.

A Quick Object Lesson

So far in this book, you’ve learned that you can write something to a Web page with the document.write() command, and to determine how many items are in an array, you type the name of the array followed by a period and the word “length,” like so: days.length. You’re probably wondering what those periods are about. You’ve made it through three chapters without learning the particulars of this feature of JavaScript syntax, and it’s time to address them.

You can conceptualize many of the elements of the JavaScript language, as well as elements of a Web page, as objects. The real world, of course, is filled with objects too, such as a dog or a car. Most objects are made ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

JavaScript & jQuery: The Missing Manual, 3rd Edition

JavaScript & jQuery: The Missing Manual, 3rd Edition

David Sawyer McFarland
JavaScript

JavaScript

T. J. Crowder

Publisher Resources

ISBN: 9780596515898Errata Page