-
Why Javascript?
Adds interactivity and visual enhancement
-
Javascript is mainly used for
- Client-side execution
- Processing client requests that do not require server processing
- No internet traffic
-
Cons of Javascript
- The client may not have enough processing resources
- Javascript can be turned off for security reasons
-
Origins of Javascript
- Developed by Netscape - Mocha, LiveScript
- Netscape and Sun collaborate - JavaScript (1994)
- Microsoft creates Jscript
- ECMAScript is now the "standard"
-
Difference between JavaScript and Java
- No graphical user interface
- No read/write file access on clients
- Not a class-based object model
- No multithreading
- Do not need the Java Virtual Machine (needs a browser)
-
What can JavaScript do on the
- Client side
- Control browser features
- Modify document appearance
- Modify document content
- Store & use information about user
- Manipulate images
- React to state of browser and client system
-
When to use Javascript
- CSS
- Hover and focus events
- Image swaps
- basic animation
- Drop-down menus
- Javascript
- Visual enhancement that CSS can't do
- Advanced animation
-
Where does one's Javascript code go?
- Embedded in HTML
- In it's own file - best way for code reuse
-
Development environment
- Text editor or HTML editor
- Browser to run and debug code
-
Variables
- Valid variable names consist of letters, digits, underscores and dollar signs
- Do not begin with a digit
- Case sensitive
- declared with var
-
Dynamic Variable Types
Like number, string, array and object
-
Arithmetic operators
- + addition
- -subtraction
- *multiplication
- /division
- %modulus (remainder)
- ++ increment
- --decrement
-
Date Method
- getHours (0-23)
- getDay (0-6)
- getDate (1-31)
- getMinutes (0-59)
- getMonth (0-11)
- getFullYear (yyyy)
-
Output's in Javascript
- window.alert() - popup message box
- document.writeln() or document.write()
-
Inputs in Javascript
- window.prompt() - input box
- confirm() - ok/cancel box
-
Debugging in Javascript
- console.log()
- Console.error()
-
Javascript built in functions
built in method of performing common math calculations, string manipulations, date and time manipulations, and manipulations of collections of data called arrays
-
3 ways to return control to the point at which the function was invoked
- Reaching the function-ending right brace
- executing the statement return;
- Executing the statement "return expression;" to return the value of expression to the caller
-
A function without a name
Anonymous function
-
A function can be considered as an _______ and referenced by a variable
object
-
What is an array
- a group of variables that have the same name and normally are of the same type
- Array contains elements
-
First element in an array is the
zeroth element
-
Used to create an array and specify the number of elements in an arrary
- New operator
- var n1 = new Array(3)
- var n2 = ["Ford", "Toyota","Honda"]
-
Javascript events
Allow scripts to respond to user interactions and modify the page accordingly
-
Events and event handeling
help make the web application more dynamic and interactive
-
Load event
- window object's load event fires when the window finishes loading successfully
- Every DOM element has a load event but the window one is most commonly used
-
A function that responds to an event
Event handler
-
Assigning an event handler to an event on a DOM node is called
registering an event handler
-
Mouse event
- Mouseover - curser enters an element
- Mouse out - curser leaves element
-
<iframe> tag indicates
there is a window object for the HTML document, and one additional window for each frame
-
Common window methods
- alert()
- setTimeout() - calls function a specificed number of miliseconds
- setInterval() - calls a function at the specified intervals
-
writeln()
writes a line of output to the document (adds new line at the end)
|
|