lwd5_chapter21.pdf - lwd5_chapter21 1 of 41...

This preview shows page 1 - 3 out of 41 pages.

learning.oreilly.comlwd5_chapter2150-63 minutesPart IV.JavaScript for Behavior21. Introduction to JavaScriptby Mat MarquisIn this chapter, I’m going to introduce you to JavaScript. Now, it’spossible you’ve just recoiled a little bit, and I understand. We’reinto full-blown “programming language” territory now, and that canbe a little intimidating. I promise, it’s not so bad!We’ll start by going over what JavaScript is—and what it isn’t—anddiscuss some of the ways it is used. The majority of the chapter ismade up of an introduction to JavaScript syntax—variables,functions, operators, loops, stuff like that. Will you be coding by theend of the chapter? Probably not. But you will have a good headstart toward understanding what’s going on in a script when yousee one. I’ll finish up with a look at some of the ways you canmanipulate the browser window and tie scripts to user actionssuch as clicking or submitting a form.What Is JavaScript?If you’ve made it this far in the book, you no doubt already knowthat JavaScript is a programming language that adds interactivitylwd5_chapter21about:reader?url=https%3A%2F%2Flearning.oreilly.com%2Flibrary%2F...1 of 418/18/21, 22:19
and custom behaviors to our sites. It is a client-side scriptinglanguage, which means it runs on the user’s machine and not onthe server, as other web programming languages such as PHPand Ruby do. That means JavaScript (and the way we use it) isreliant on the browser’s capabilities and settings. It may not evenbe available at all, either because the user has chosen to turn it offor because the device doesn’t support it, which good developerskeep in mind and plan for. JavaScript is also what is known as adynamic and loosely typed programming language. Don’t sweatthis description too much; I’ll explain what all that means later.First, I want to establish that JavaScript is kind of misunderstood.What It Isn’tRight off the bat, the name is pretty confusing. Despite its name,JavaScript has nothing to do with Java. It was created by BrendanEich at Netscape in 1995 and originally named “LiveScript.” ButJava was all the rage around that time, so for the sake ofmarketing, “LiveScript” became “JavaScript.” Or just “JS,” if youwant to sound as cool as one possibly can while talking aboutJavaScript.JS also has something of a bad reputation. For a while it wassynonymous with all sorts of unscrupulous internet shenanigans—unwanted redirects, obnoxious pop-up windows, and a host ofnebulous “security vulnerabilities,” just to name a few. There was atime when JavaScript allowed less reputable developers to do allthese things (and worse), but modern browsers have largelycaught on to the darker side of JavaScript development and lockedit down. We shouldn’t fault JavaScript itself for that era, though. Aslwd5_chapter21about:reader?url=https%3A%2F%2Flearning.oreilly.com%2Flibrary%2F...

Upload your study docs or become a

Course Hero member to access this document

Upload your study docs or become a

Course Hero member to access this document

End of preview. Want to read all 41 pages?

Upload your study docs or become a

Course Hero member to access this document

Term
Fall
Professor
staff
Tags
Closure

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture