JavaScript Absolute Beginner's Guide

 JavaScript

Kirupa Chinnathambi

Pearson Education 800 East 96th Street Indianapolis, Indiana 46240 USA

JavaScript Absolute Beginner's Guide

Copyright ? 2017 by Pearson Education

All rights reserved. No part of this book shall be reproduced, stored in a retrieval system, or transmitted by any means, electronic, mechanical, photocopying, recording, or otherwise, without written permission from the publisher. No patent liability is assumed with respect to the use of the information contained herein. Although every precaution has been taken in the preparation of this book, the publisher and author assume no responsibility for errors or omissions. Nor is any liability assumed for damages resulting from the use of the information contained herein.

ISBN-13: 978-0-7897-5806-4 ISBN-10: 0-7897-5806-7

Library of Congress Control Number: 2016939721

Printed in the United States of America

First Printing: July 2016

Trademarks

All terms mentioned in this book that are known to be trademarks or service marks have been appropriately capitalized. Pearson cannot attest to the accuracy of this information. Use of a term in this book should not be regarded as affecting the validity of any trademark or service mark.

Warning and Disclaimer

Every effort has been made to make this book as complete and as accurate as possible, but no warranty or fitness is implied. The information provided is on an "as is" basis. The author and the publisher shall have neither liability nor responsibility to any person or entity with respect to any loss or damages arising from the information contained in this book.

Special Sales

For information about buying this title in bulk quantities, or for special sales opportunities (which may include electronic versions; custom cover designs; and content particular to your business, training goals, marketing focus, or branding interests), please contact our corporate sales department at corpsales@ or (800) 382-3419.

For government sales inquiries, please contact governmentsales@.

For questions about sales outside the U.S., please contact intlcs@.

Acquisitions Editor Mark Taber

Development Editor Chris Zahn

Copy Editor Autumn Spalding

Production Editor Lori Lyons

Technical Editors Trevor McCauley Kyle Murray

This page intentionally left blank

Contents at a Glance

Introduction ................................................................................................ 1 1 Hello, World!............................................................................................... 5

Part I

2 3 4 5 6 7 8 9 10

The Basic Stuff

Values and Variables ................................................................................ 13 Functions................................................................................................... 19 Conditional Statements: If, Else, and Switch ........................................ 31 Meet the Loops: For, While, and Do...While!....................................... 47 Timers........................................................................................................ 59 Variable Scope.......................................................................................... 67 Closures..................................................................................................... 77 Where Should Your Code Live?.............................................................. 89 Commenting Your Code .......................................................................101

Part II

11 12 13 14 15 16 17 18 19 20

It's an Object-Oriented World

Of Pizza, Types, Primitives, and Objects .............................................109 Strings...................................................................................................... 121 When Primitives Behave Like Objects .................................................133 Arrays....................................................................................................... 139 Numbers.................................................................................................. 149 A Deeper Look at Objects ....................................................................161 Extending Built-in Objects .................................................................... 179 Booleans and the Stricter === and !== Operators ...........................189 Null and Undefined................................................................................195 Immediately Invoked Function Expressions ........................................201

Part III

21 22 23 24 25 26 27

Working with the DOM

JS, The Browser, and The DOM ...........................................................219 Finding Elements in the DOM..............................................................231 Modifying DOM Elements ....................................................................237 Styling Your Content..............................................................................247 Traversing the DOM...............................................................................255 Creating and Removing DOM Elements.............................................265 In-Browser Developer Tools ..................................................................279

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download