JavaScript gives HTML designers a programming tool HTML authors are normally

Javascript gives html designers a programming tool

This preview shows page 31 - 42 out of 96 pages.

JavaScript gives HTML designers a programming tool - HTML authors are normally not programmers, but JavaScript is a scripting language with a very simple syntax! Almost anyone can put small "snippets" of code into their HTML pages JavaScript can put dynamic text into an HTML page - A JavaScript statement like this: document.write ("<h1>" + name + "</h1>") can write a variable text into an HTML page
Image of page 31
32 What can a JavaScript Do?
Image of page 32
33 What can a JavaScript Do? JavaScript variables can hold: Numbers: integer and floating point Booleans: true, false Strings: "Hello World!" Objects: myObj = new Object(); Null: empty, no value
Image of page 33
34 What can a JavaScript Do? JavaScript Operators The usual range of comparison and arithmetic operators. String concatenation with +: "Age:" + "20" gives "Age: 20 " C style conditional operators: preferredPet = (cats > dogs) ? "felines" : "canines"
Image of page 34
35 JavaScript Web servers Web browser Request HTML page with JavaScript JavaScript response
Image of page 35
36 JavaScript variables JavaScript variables are used to hold values or the results of expressions. Declare variables var x=5; // after execution x has value 5, or use x=5 ; var carname="Volvo"; Rules for JavaScript variable names: Variable names are case sensitive (y and Y are two different variables) Variable names must begin with a letter or the underscore character followed by letters, digits or underscore character Avoid reserve words which have special meanings in the programming language, like for , var , while and function Give memorable and meaningful names, like age, name, subject, carname etc
Image of page 36
; ;
Image of page 37
38 JavaScript variables Special characters – they all begin with a backslash character (\) Output Character Special Code to Use Backslash (\) \\ Double quote (") \" Single Quote (‘) \’ Tab \t
Image of page 38
Image of page 39
40 JavaScript operators operators types Mathematical Assignment Comparison Logical
Image of page 40
41 JavaScript operators Given y=8, the following table explains mathematical operators operator description example Result of x + Addition x=2+3 5 - Subtraction x=y-5 3 * Multiplication x=y*2 16 / Division x=y/2 4 % Modulus (division remainder) x=y%3 2 ++ Increment x=++y 9 -- Decrement x=--y 1
Image of page 41
Image of page 42

You've reached the end of your free preview.

Want to read all 96 pages?

  • Three '20

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture