Download Head First JavaScript Programming - Wickedly Smart PDF

TitleHead First JavaScript Programming - Wickedly Smart
File Size18.6 MB
Total Pages83
Document Text Contents
Page 41

this is a new chapter 1

Getting your feet wet
1 a quick dip into javascript

Come on in, the water’s
great! We’re going to dive

right in and check out JavaScript,
write some code, run it and watch it

interact with your browser! You’re
going to be writing code in no


JavaScript gives you superpowers. The true programming
language of the web, JavaScript lets you add behavior to your web pages. No

more dry, boring, static pages that just sit there looking at you—with JavaScript

you’re going to be able to reach out and touch your users, react to interesting

events, grab data from the web to use in your pages, draw graphics right in your

web pages and a lot more. And once you know JavaScript you’ll also be in a

position to create totally new behaviors for your users.

You’ll be in good company too, JavaScript’s not only one of the most popular

programming languages, it’s also supported in all modern (and most ancient)

browsers; JavaScript’s even branching out and being embedded in a lot of

environments outside the browser. More on that later; for now, let’s get started!

Page 42

2 Chapter 1

how javascript works

The way JavaScript works

So let’s introduce JavaScript, HTML & CSS’s
computational cousin. JavaScript lets you create
behavior in your web pages. Need to react when a
user clicks on your “On Sale for the next 30 seconds!”
button? Double check your user’s form input on the fly?
Grab some tweets from Twitter and display them? Or
how about play a game? Look to JavaScript. JavaScript
gives you a way to add programming to your page so
that you can compute, react, draw, communicate, alert,
alter, update, change, and we could go on... anything
dynamic, that’s JavaScript in action.

And you already know that we
use CSS, or Cascading Style
Sheets, to specify how the
HTML is presented...the colors,
fonts, borders, margins, and
the layout of your page. CSS
gives you style, and it does it
in a way that is separate from
the structure of the page.

You already know
we use HTML, or
Hypertext Markup
Language, to specify
all the content of
your pages along
with their structure,
like paragraphs,
headings and



If you’re used to creating structure, content, layout and style in your web pages,
isn’t it time to add a little behavior as well? These days, there’s no need for
the page to just sit there. Great pages should be dynamic, interactive, and they
should work with your users in new ways. That’s where JavaScript comes in.
Let’s start by taking a look at how JavaScript fits into the web page ecosystem:


Page 82

42 Chapter 1

exercise solutions


All our methods of communication have come to the party with masks on. Can you help us unmask
each one? Match the descriptions on the right to the names on the left. Here’s our solution:




document object model

I ’ l l stop your user in his tracks and deliver a short
message. The user has to click “ok” to go further.

I can insert a little HTML and text into a document.
I’m not the most elegant way to get a message to
your users, but I work on every browser.

Using me you can totally control a web page: get
values that a user typed in, alter the HTML or the style,
or update the content of your page.

I’m just here for simple debugging purposes. Use
me and I can write out information to a special
developer ’s console.


Page 83

O’Reilly Media spreads the knowledge of innovators
through its books, online services, magazines, research,
and conferences. Get the information you need from the
experts you trust; visit to purchase this book.

Get 40% off of the print book by entering
discount code HFJSP.

Head First JavaScript Programming
By Eric T. Freeman, Elisabeth Robson
Mar 2014, ISBN 978-1-4493-4013-1
704 pages, $49.99

Spreading the knowledge of innovators

Head First JavaScript

Similer Documents