Académique Documents
Professionnel Documents
Culture Documents
HTML, Introduction to JavaScript, OOP in JavaScript, XML and JavaScript, AJAX as a Concept
What is JavaScript?
JavaScript adds animation, interactivity and visual effects to your HTML. JavaScript makes immediate feedback possible! This allows for JavaScript powered pages to instantly return results as forms are submitted. The same thing goes with error messages, they can easily be given just before the form is submitted. JavaScript also allows for interactive interfaces! You can turn thumbnails into slideshows, organize content into panels for visitors to easily click, create pop up tool tips that give users supplemental information.
What is JavaScript?
One of the key selling points of JavaScript is immediacy. It allows for instant response when actions like clicking, filling out forms and moving mouse happen. JavaScript never suffers from server-side delay from programming languages like PHP because it doesnt rely on browser-server communication.
What is jQuery?
Writing JavaScript is hard even though its simpler than most programming languages. Writing JavaScript code is hard because different browsers understand JavaScript differently so sometimes applications written on Google Chrome dont work on Internet Explorer 9. This bug eats up a lot of development time as developers try to make sure that their application works for the whole audience.
What is jQuery?
jQuery is a JS library that makes programming more easier and more fun. jQuery solves cross browser testing, and other difficult tasks. jQuery allows designers to easily create interfaces that JavaScript would otherwise take nearly forever to create. It allows you to easily use plugins to add new features.
Statements
A JS statement is the basic programming unit in the script. All lines of a script is a statement. Example:
alert('Hello World!');
Data Types
There are three basic data types in JavaScript:
number string Boolean
Numbers
Numbers is the equivalent of the Number class in Java. This allows you to easily manipulate data in any format, as in doubles, integers and bytes.
Aside from numbers, JS also supports operators to manipulate these data sets.
Strings
Unlike Strings in Java JavaScript Strings can also be enclosed in single quotes. Either way, Strings in JavaScript are still the same as they are a sequence of letters.
Make sure of course that you use the corresponding closing mark when enclosing a String.
Remember to place appropriate escape characters as well when placing quotes.
Booleans
Much like other Boolean values in Java it can only be true or false.
Variables
To create a variable type in JavaScript, we write:
var score;
Since JavaScript is dynamically typed, this variable can handle any data type. The same naming conventions that apply to Java identifiers apply to JavaScript variables.
Operators
Notes
Take note that the same evaluation rules apply as with Java operators. That is:
4 + 5 * 10 is still evaluated as 54
To allow lower ordered operators to be evaluated first, use parentheses for grouping.
Adding Strings
Similar to Java, we can concatenate strings using the + operator.
Equivalence Operators
Arrays
The code above creates an array in JS. Take note that it uses square brackets and not curly brackets.
Arrays
Since JS is dynamically typed, an array can have different kinds of data
Accessing Arrays
JS is implements 0 indexing so accessing an element is always its placement in the array minus 1.
Length of an Array
Adding to an Array
You can add more than one value to an array.
Conditional Statements
The code above shows the syntax for an if statement in JS.
Comparison Operators
Comparison Operators
Conditional Statement
The line of code from above shows how if-else statements in JS are done.
Conditional Statement
The lines of code above show how if-else-elseif statements are made in JS.
for-loop statement
The following lines of code show how a for-loop statement is made in JS.
Looping Statements
The following lines of codes show how a do-while loop is done in JS.
Functions
The line of code
Functions
The following lines of code show us how to return a value after creating a function in JS.
JavaScript OOP
JavaScript allows for robust object-oriented programming, by using the function syntax to create objects. Similar to Java, the only way to construct a new object is to invoke the new keyword.
JavaScript OOP
JavaScript OOP
Another way to add functions to JavaScript objects after they have been defined is to use the prototype method. Think of this as some kind of inheritance where the new function is added after the object has already been defined.
JavaScript OOP
JavaScript OOP
Sources
JavaScript and jQuery The Missing Manual 2nd edition, David Sawyer McFarland http://www.javascriptkit.com/javatutors/oopj s2.shtml