Sams Teach Yourself HTML, CSS & JavaScript Web Publishing in One Hour a Day

(singke) #1
ptg16476052

496 LESSON 17: Introducing JavaScript


Q What is AJAX?
A One topic we haven’t covered yet is AJAX. AJAX is a term used to describe scripts
that communicate with the server without requiring a web page to be fully reloaded.
For example, you can use it to fetch information and display it on the page or to
submit a form for processing, all without changing the full page in the browser.
Q When I use JavaScript, do I need to accommodate users whose browsers may
not support JavaScript or who have disabled it?
A Some estimates indicate that over 95% of web users have JavaScript enabled.
However, unless you have a really good reason not to, you should make accom-
modations for users without JavaScript. You need not offer users who don’t have
JavaScript an identical experience to those who have it, but they should be able to
access your site. For example, if you run an online store, do you really want to shut
out users because of their browser configuration?
Q In Java and C++, I previously defined variables with statements such as int,
char, and String. Why can’t I do this in JavaScript?
A As I mentioned previously, JavaScript is a loosely typed language. This means that
all variables can take any form and can even be changed on-the-fly. As a result, the
context in which the variable is used determines its type.

Quiz



  1. What HTML tag is used to embed JavaScript scripts in a page?

  2. What are events? What can JavaScript do with them?

  3. Is an expression that evaluates to the value 0 true or false? How about the string
    "false" inside quotation marks?

  4. How do you make sure that a variable you create in a function is only visible
    locally in that function?

  5. How are functions different from methods?


Quiz Answers



  1. To accommodate the inclusion of JavaScript programs in a normal HTML docu-
    ment, Netscape introduced the