Tải bản đầy đủ (.pdf) (501 trang)

JAVASCRIPT programming(2 edition), learn coding fast (with 100 tests answers) crash course, quick start guide, tutorial book with hands on projects in easy steps an ultimate beginner s guide

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (921.59 KB, 501 trang )


JavaScript
Programming
By Ray Yao
For Beginners
(With 100 Tests & Answers)


Copyright © 2015 by Ray Yao
All Rights Reserved
Neither part of this book nor whole of this book may be reproduced or
transmitted in any form or by any means electronic, photographic or
mechanical, including photocopying, recording, or by any information
storage or retrieval system, without prior written permission from the author.
All Right Reserved!
Ray Yao
About the Author
Ray Yao:
Certified PHP engineer by Zend, USA
Certified JAVA programmer by Sun, USA
Certified SCWCD developer by Oracle, USA
Certified A+ professional by CompTIA, USA
Certified ASP. NET expert by Microsoft, USA
Certified MCP professional by Microsoft, USA
Certified TECHNOLOGY specialist by Microsoft, USA
Certified NETWORK+ professional by CompTIA, USA


Highly Recommend Computer Books on Amazon:
Linux Command Line
JAVA Programming


PHP Programming
JavaScript Programming
C++ Programming
AngularJS Programming
JQuery Programming
Python Programming
HTML CSS Programming
C# Programming
Visual Basic Programming
JavaScript 50 Useful Programs
Advanced Java Programming
Advanced C++ Programming


Preface
“JavaScript Programming” covers all essential JavaScript knowledge. You
can learn complete primary skills of JavaScript fast and easily.
This book includes many practical Hands-On Projects. You can study
JavaScript coding with Hands-On Projects.

Source Code for Download
This book provides source code for download; you can download the source
code for better study, or copy the source code to your favorite editor to test
the programs. The download link of the source code is at the last page of this
book.
Start Coding Today!


Table of Contents
Hour 1 JavaScript Basic

What is JavaScript?
Comment
Run First Program
Keywords
Variables
Data Types
Escape Sequences
Functions
Function with Arguments
Return Values
Variable Scope
Show the Texts
Undefined Variable
Rule of Variable Naming
Hands-On Project: A Simple Call

Hour 2 Operators
Arithmetical Operators
Logical Operators
Assignment Operators
Comparison Operators
Conditional Operator
If Statement
If-else Statement
Switch Statement


For Loop
While Loop
Do-While Loop

Break Statement
Continue Statement
Hands-On Project: Number One

Hour 3 Array
Create an Array
Show array element values
Get the Size of Array
Join Array Elements
Reverse Element Order
Slice Elements
Sort Elements in Order
Change Elements to String
Search Specific Element (1)
Search Specific Element (2)
Add Element to Beginning
Remove First Element
Add Element to End
Remove Last Element
Hands-On Project: Reverse Order

Hour 4 Math, Time
Math Methods
Greater & Less
Maximum & Minimum
Power Value


Square Root
PI & Random Value

Date & Time
Date, Month, Year, Day
Hours, Minutes, Seconds
Different Time
Set Date & Time
Timer Function
Hands-On Project: This Month…

Hour 5 String
String length
Join Strings
Search a Character
Convert Character Case
Change String to Array
Extract Substring
Convert a Number to String
Convert a String to a Number
Search Specific Text (1)
Search Specific Text (2)
Unicode
Add a Link for Text
Hands-On Project: UpperCase

Hour 6 Object
Object Declaration
Navigate Web Page
Go to Specified Page


Open Customized Window

Close Current Window
Confirmation
Prompt to Input
Address Element by ID
Get Elements by Tag Name
Connect two Strings
Convert Number to String
From Jan, 1, 1970
Absolute Value
Print Current Window
Check Java Enabled
Screen’s Width & Height
Hands-On Project: Max & Min

Hour 7 Event
HTML Basic
Click Event
Load Event
KeyPress Event
Mouseover Event
MouseOut Event
Keyup Event
Focus Event
Blur Event
Reset Event
Submit Event
Hands-On Project: Mouse Out


Hour 8 Form & Dom

Form Basic
The Element of the form
Access the Form
Set ID for a Form
Show the Value of an Element
Input Data to Form
Show What Inputted
Reset Method
Submit Method
“Select” Selection
“Radio” Selection
“CheckBox” Selection
Submit the Form
DOM: CreateElement( )
DOM: CreateTextNode( )
DOM: set/getAttribute( )
DOM: hasChildNodes( )
Hands-On Project: Clear Anything

Appendix JavaScript 100 Tests & Answers
100 Tests
100 Answers

Source Code for Download


Hour 1


JavaScript Basic



What is JavaScript?
JavaScript is a dynamic computer programming language used to make web
pages interactive. Its interpreter is embedded inside web browser software,
such as IE, Chrome, and Firefox etc. It runs on visitor's computer and
browser.
The syntax of JavaScript looks like this:
<script type = “text/javascript”>
……
</Script>


Example 1.1
<html>
<head>
<title>Hello World</title>
</head>
<body>
<script language="javascript">
alert("Hello World!");
</script>
</body>
</html>


Output:
Hello World!



Explanation:
“<script type = “text/javascript”>” is a tags for JavaScript. The JavaScript
codes are included within it.
“alert” pops up an alert box displaying a message.
“alert (“Hello World!”)” displays “Hello World!” message.
Each JavaScript command ends with semicolon;
JavaScript block can locate anywhere in HTML file.


Comment
Comment is used to explain the code.
// This is a single line comment
/* This is a multi line comment; JavaScript
interpreter will ignore both single line comment and
multi line comment.
*/


Example 1.3
<script type = “text/javascript”>
alert (“Hello World”); // “alert” pops up a message.
/* “alert” pops up an alert box displaying a message
“Hello World”. “alert( )” is usually used if you want to make sure message
comes through to the user. */
</Script>


Explanation:
// “alert” pops up a message is a single line comment.
/* “alert” pops up an alert box displaying a message “Hello World”. …… */

is a multi line comment.

- -> is a html comment.


Run First Program


Example 1.2
“Hello World!” program:
Open Notepad, write JavaScript codes as following:
(Figure 1.1)
<html>
<head>

<!- - this is a html file - ->

<title>
The first JavaScript Program
</title>
<head>
<body>
<script language="javascript"> // start javascript
document.write ("

Hello World!

") // output
</script>
</body>
</html>

(Figure 1.1 Write JavaScript codes to Notepad)

Please save the file with name “FirstJavaScript.html”.
Note: make sure to use “.html” extension name.
Double click “FirstJavaScript.html” file, the “FirstJavaScript.html” will be
run by a browser, and see the output. (Figure 1.2)


Output:

(Figure 1.2)
“document.write ("

Hello World!

")” outputs “Hello World!”
If you want to edit the codes, right click the file “FirstJavaScript.html” >
open with > Notepad.


Keywords
Keywords belong to JavaScript itself. These may not be used when choosing
identifier names for variables, functions, properties. The following are
JavaScript keywords:
break

case

continue

default

delete

do


else

export

false

for

function

if

import

in

new

null

return

switch

this

true

typeof


var

void

while

with

Array

Date

Math

Object

window

location

history

navigator document images
forms

elements

links

getElementById innerHTML



Example 1.4
break // this is a JavaScript keyword.
return // this is a JavaScript keyword.


Explanation:
JavaScript keyword may not be used when choosing identifier names for
variables, functions, properties.


×