Since its release in December 4, 1995 [six months after Java, which was released in May 23, 1995], JavaScript has gone through many changes. JavaScript bắt đầu là ngôn ngữ lập trình phía máy khách [chạy bên trong trình duyệt web thông qua công cụ JavaScript tích hợp] để thêm nội dung tương tác vào trang web. It became more robust with DHTML [1997] and Ajax [1999]. With Node. js [released in May 27, 2009], JavaScript can be used to program server-side and build full-stack web applications. In 2015, the ECMAScript 6 [ES6] introduces major update to the language
Introduction
It began as a Client-side Programming Language run inside a web browser via a Built-in JavaScript EngineJavaScript is the most widely used client-side programming language that lets you supercharge your HTML with interactivity, animation and dynamic visual effect for better User Interface and User Experience [UI/UX]. It is
- a small, lightweight, object-oriented, cross-platform, special-purpose scripting language meant to be run under a host environment [typically a web browser]
- a client-side scripting language to enrich web user-interfaces and create dynamic web pages [e. g. , xác thực đầu vào biểu mẫu và phản hồi ngay lập tức cho hành động của người dùng]
- công cụ hỗ trợ AJAX [JavaScript và XML không đồng bộ - có thể được sử dụng để cập nhật một phần của trang web một cách không đồng bộ], tạo ra sự quan tâm mới đối với JavaScript
JavaScript hoạt động cùng với HTML/CSS. HTML cung cấp nội dung; . Cùng nhau, chúng làm phong phú UI/UX của người dùng web
JavaScript hiện có ở mọi nơi với Node. jsJavaScript đã phát triển vượt ra ngoài lập trình phía máy khách. Với sự ra đời của Node. js vào năm 2009 [môi trường thời gian chạy JavaScript đa nền tảng, mã nguồn mở], bạn có thể chạy JavaScript độc lập hoặc bên trong máy chủ [thay vì trình duyệt]. Điều này cho phép bạn sử dụng một ngôn ngữ duy nhất cho cả lập trình phía máy chủ và phía máy khách
Lịch sử và Phiên bảnJavaScript, ban đầu được gọi là LiveScript, được tạo bởi Brendan Eich tại Netscape vào năm 1995. Ngay sau đó, Microsoft đã tung ra phiên bản JavaScript của riêng mình có tên là JScript. Sau đó, Netscape gửi nó lên ECMA [trước đây là "Hiệp hội các nhà sản xuất máy tính châu Âu", nay là "Ecma International - hiệp hội tiêu chuẩn hóa hệ thống thông tin và truyền thông châu Âu"] để chuẩn hóa, cùng với JScript của Microsoft.
Đặc tả ECMA được gọi là "Đặc tả ngôn ngữ ECMA-262 ECMAScript" @ http. //www. ecma-quốc tế. org/ấn phẩm/tiêu chuẩn/Ecma-262. htm [also approved as "ISO/IEC 16262"]
- ECMA-262 phiên bản 1 [tháng 6 năm 1997]. First edition
- ECMA-262 version 2 [August 1998]
- ECMA-262 version 3 [December 1999]. Added regular expressions, try/catch, switch, do-while, etc
- ECMA-262 version 4 - Abandon due to political differences. In 2007, the TC-39 [the committee responsible for ECMAScript] put up a draft specification for ECMAScript 4, which was massive in scope and introduced many new syntax and features. But a group of developers from Yahoo, Google and Microsoft felt that was too much and created an alternate proposal called ECMAScript 3. 1. ECMAScript 4 was never finalized
- ECMA-262 version 5 and 5. 1 [June 2011]. ECMAScript 3. 1 cuối cùng đã được chuẩn hóa thành ECMAScript 5. Đã thêm "chế độ nghiêm ngặt", phương thức lặp JSON, Array, v.v.
- ECMA-262 2015. phổ biến nhất được gọi là ECMAScript 6 hoặc ES6.
Phiên bản này đã thêm cú pháp mới quan trọng để viết ứng dụng phức tạp, bao gồm khai báo lớp,
0 cho khai báo cục bộ,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
1 cho khai báo cục bộ không đổi, giá trị tham số mặc định, bộ lặp và cho. của các vòng lặp, trình tạo kiểu Python, biểu thức hàm mũi tên [_______02], dữ liệu nhị phân, mảng đã nhập, bộ sưu tập mới [bản đồ, bộ và Bản đồ yếu], lời hứa, sự phản chiếu, proxy, chữ mẫu cho chuỗi, v.v.JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
- ECMAScript 2016 [ES7]. Kể từ ES6, các tiêu chuẩn ECMAScript sẽ có chu kỳ phát hành hàng năm vào tháng 6.
Phiên bản này đã thêm toán tử hàm mũ [
3], phạm vi khối của các biến và hàm, từ khóaJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
4 vàJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
5 cho lập trình không đồng bộ, v.v.JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
- ECMAScript 2017 [ES8]. Đã thêm phần đệm chuỗi, các hàm không đồng bộ sử dụng trình tạo và lời hứa,
6,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
7 để thao tác đối tượng dễ dàng, v.v.JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
- ECMAScript 2018 [ES9]. Đã thêm tham số phần còn lại [
8], toán tử trải rộng, phép lặp không đồng bộ, bổ sung cho biểu thức chính quyJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
- ECMAScript 2019 [ES10]. Đã thêm
9,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
00, thay đổiJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
01 vàJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
02, ràng buộc bắt trở thành tùy chọn, v.v.JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
- ECMAScript 2020 [ES11]. giới thiệu một kiểu nguyên thủy
03 cho các số nguyên có kích thước tùy ý, toán tử kết hợp nullish [JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
04] và đối tượngJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
05JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
- ECMAScript 2021 [ES12]. Đã thêm tính năng nâng cao cho chuỗi [
06], lời hứa [JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
07] và tham chiếu đối tượng. Toán tử gán logic [JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
08,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
09,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
000,]JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
Java là một ngôn ngữ lập trình đa năng chính thức. Nó được tạo ra bởi James Gosling tại Sun Microsystems [nay là một phần của Oracle] và phát hành vào tháng 8 năm 1995
JavaScript được tạo bởi Brendan Eich tại Netscape, cũng vào năm 1995. Ban đầu được gọi là LiveScript, nó là một ngôn ngữ chuyên dụng nhỏ và nhẹ để viết chương trình phía máy khách chạy bên trong trình duyệt để tạo giao diện người dùng hoạt động và tạo các trang web động. Nó được đổi tên thành JavaScript trong một quyết định tiếp thị tồi tệ nhằm cố gắng tận dụng sự phổ biến của ngôn ngữ Java, khi Netscape phát hành Navigator 2 vào năm 1996
Java và JavaScript là các ngôn ngữ hoàn toàn khác nhau cho các mục đích lập trình khác nhau. Tuy nhiên, trong những ngày đầu, một số nỗ lực đã được thực hiện để áp dụng cú pháp và quy ước của Java vào JavaScript, vì vậy JavaScript dường như là một tập hợp con của Java. Trên thực tế, chúng có rất ít điểm chung
JavaScript phía máy khách KHÔNG THỂ làm gì?Hãy nhớ rằng JavaScript là chương trình phía máy khách mà bạn đã tải xuống từ máy chủ và chạy bên trong trình duyệt của máy [máy khách] của bạn. Làm gì để ngăn ai đó viết JavaScript xóa sạch đĩa cứng của bạn hoặc kích hoạt một cuộc tấn công từ chối dịch vụ tới một máy chủ khác?
- Nó không thể đọc tệp từ máy của khách hàng
- Nó chỉ có thể kết nối với máy chủ mà nó đến từ đó. Nó có thể đọc tệp từ máy chủ mà nó đến từ. Nó không thể ghi tập tin vào máy chủ
- Nó không thể kết nối với máy chủ khác
- Nó không thể đóng một cửa sổ mà nó không mở
jQuery là một thư viện JavaScript đa trình duyệt phổ biến. jQuery là JavaScript [nhưng có cú pháp mở rộng riêng], do đó, bạn cần hiểu JavaScript. Tôi khuyên bạn nên đọc qua cú pháp JavaScript [và đặc biệt chú ý đến các đối tượng], sau đó chuyển sang jQuery để sản xuất. Đọc "Thông tin cơ bản về jQuery"
JavaScript độc lập và phía máy chủ với nút. Công cụ JavaScript js[LÀM]
Trình chỉnh sửa mã nguồn JavaScript và IDEBạn cần một trình soạn thảo văn bản để viết JavaScript của mình. Bạn có thể sử dụng trình soạn thảo văn bản thuần túy như NotePad của Windows hoặc TextEdit của macOS [hoàn toàn KHÔNG được khuyến nghị vì chúng không thể tô sáng cú pháp]. Để cải thiện năng suất của bạn, một trình chỉnh sửa mã nguồn tốt [cung cấp tính năng tô sáng cú pháp, tự động hoàn thành mã, đoạn mã, tài liệu, điều hướng ký hiệu, tái cấu trúc, v.v. ] là điều cần thiết. Có rất nhiều phần mềm miễn phí/phần mềm chia sẻ, chẳng hạn như Visual Studio Code [VS Code], Sublime Text, Atom, Brackets, Komodo Edit, Emacs, Vim, BBEdit, TextMate, NotePad++ [Windows], v.v. Bạn cũng có thể sử dụng IDE quy mô đầy đủ như Eclipse, NetBeans, IntelliJ IDEA. Ngoài ra còn có nhiều trình soạn thảo và trình biên dịch "trực tuyến" [e. g. , Programiz, JSFiddle, Playcode], nhưng tôi nghĩ rằng bạn nên cài đặt của riêng mình
Ví dụ JavaScript phía máy khách
Tôi sẽ cho rằng bạn biết HTML và CSS [hãy đọc các bài viết về HTML/CSS của tôi nếu không]. Tôi cũng sẽ cho rằng bạn hiểu một số điều cơ bản về lập trình [tư duy tính toán] chẳng hạn như biến, cấu trúc if-else và vòng lặp for
JavaScript phía máy khách chạy bên trong trình duyệt thông qua công cụ JavaScript tích hợp. Có các tiêu chuẩn về JavaScript. Nhưng Big-5 [Chrome, Firefox, IE/Edge, Safari và Opera], đặc biệt là IE, không tuân thủ nghiêm ngặt tất cả các tiêu chuẩn. Hơn nữa, họ tạo tiện ích mở rộng của riêng mình. Do đó, hành vi của JavaScript có thể khác nhau trong các trình duyệt khác nhau. Bạn có thể cần kiểm tra JavaScript của mình trên nhiều trình duyệt
JavaScript cũng chạy độc lập [và trong máy chủ]. Để chạy JavaScript độc lập, bạn cần cài đặt Node. js, một công cụ JavaScript. Tôi sẽ trình bày các ví dụ trong phần tiếp theo
JS phía máy khách EG 1. Hàm
JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
001 và
JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
002
JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
Hãy để chúng tôi viết JavaScript phía máy khách đầu tiên của chúng tôi để in thông báo "Xin chào, thế giới"
Bắt đầu với một tệp mới và nhập các mã sau. Không nhập số dòng, được sử dụng để hỗ trợ giải thích. lưu ý rằng
- JavaScript phân biệt chữ hoa chữ thường.
003 KHÔNG phải làJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
004 và KHÔNG phải làJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
005JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
- Khoảng trắng "thêm" [khoảng trống, tab và dòng mới] bị bỏ qua. Nghĩa là, nhiều khoảng trắng được coi là một ký tự trống. Bạn có thể sử dụng chúng một cách tự do để làm cho chương trình của bạn dễ đọc hơn
Lưu tệp dưới dạng "
JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
006" [hoặc bất kỳ tên tệp nào bạn thích, với phần mở rộng tệp là "
JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
007" hoặc "
JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
008"]. Chạy tập lệnh bằng cách tải tệp HTML vào trình duyệt hỗ trợ JavaScript [e. g. , Một trong BIG FIVE - Chrome, Firefox, Internet Explorer/Edge, Safari hoặc Opera]
JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
9Làm thế nào nó hoạt động?- JavaScript là mã lập trình được nhúng bên trong tài liệu HTML. Các mã được chứa giữa một cặp thẻ
009, như sau. GHI CHÚ. Trong HTML4/XHTML, bạn cần thêm thuộc tínhJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
010 vào phần tửJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
009. Dòng 7-9 và Dòng 13-17 là hai đoạn mã JavaScript, được đặt lần lượt trong phầnJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
012 vàJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
013JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
- Các câu lệnh JavaScript được kết thúc bằng dấu chấm phẩy
014 [như Java/C/C++/C#]JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
- Hàm
015 [Dòng 8] bật ra hộp thoại hiển thịJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
016 và nút OK. Các chuỗi được đặt trong cặp dấu nháy kép hoặc nháy đơn, e. g. ,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
017 hoặcJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
018JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
- Trang web hiện tại được đại diện bởi cái gọi là đối tượng
019 trong JavaScript. Thuộc tínhJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
020 [Dòng 16] lưu trữ ngày sửa đổi cuối cùng của tài liệu hiện tại. HàmJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
021 [Dòng 14 đến 16] có thể được sử dụng để ghiJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
016 đã chỉ định vào tài liệu hiện tại, như một phần của tài liệu HTML hiện tạiJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
- Toán tử
023 [Dòng 16] có thể được sử dụng để nối hai chuỗi [như Java]JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
- Theo kết quả của
002, phầnJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
013 của tài liệu này chứa.JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
0JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
015 vàJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
021 là một số hàm tích hợp thường được sử dụng được cung cấp trong JavaScriptJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
CỐ GẮNG. In tiêu đề của tài liệu và vị trí URL. [Gợi ý. sử dụng thuộc tính
JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
028 và
JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
029. ]Không bị bộ nhớ cache bắt - Thực hiện Control-Refresh [hoặc Control-F5]
Nếu bạn sửa đổi mã và tải lại trang web, mã mới có thể không được thực thi vì trình duyệt lưu phiên bản đã tải trước đó vào bộ đệm. Bạn có thể sử dụng Control-F5 [Control-Refresh] để yêu cầu trình duyệt loại bỏ bộ đệm và tìm nạp một trang mới
JS phía máy khách EG 2. Biến và Hàm ________ 2030, ________ 2031
Tập lệnh này nhắc người dùng nhập tên của họ, xác nhận tên và in thông báo chào mừng
Có ba loại hộp thoại bật lên để tương tác với người dùng
- Hàm
015 đặtJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
016 trên hộp bật lên có nút OK. Người dùng cần nhấp vào nút OK để tiếp tụcJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
- Hàm
034 hiển thị hộp bật lên đầu vào vớiJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
035 bằng các nút OK và Hủy. Nó trả về đầu vào do người dùng nhập dưới dạng một chuỗi; . Tham số tùy chọnJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
037 chỉ định chuỗi ban đầu sẽ được hiển thị. Trong bài viết này mình sẽ chỉ ra các tham số chức năng tùy chọn có đuôi làJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
038 cho gọnJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
- Hàm
039 đặtJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
040 trên hộp bật lên có nút OK và Hủy. Nó trả vềJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
041 nếu người dùng nhấn nút OK;JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
5Làm thế nào nó hoạt động?- Dòng 8 khai báo một biến toàn cục có tên là
043, thông qua từ khóaJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
044. Một biến là một vị trí lưu trữ được đặt tên chứa một giá trị. Khi biến được khai báo, bạn có thể gán [và gán lại] một giá trị cho biến đó, thông qua toán tử gánJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
045 [Dòng 9]JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
- Dòng 9 gọi hàm
034 để bật ra một hộp thoại và đọc chuỗi do người dùng nhập vào. Chuỗi đọc được gán cho biếnJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
043. HàmJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
030 tương tự như hàmJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
001, nhưng nó chấp nhận đầu vào của người dùngJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
- Ở Dòng 10, hàm
039 hiển thị thông báo và trả vềJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
041 hoặcJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
042, tùy thuộc vào việc người dùng nhấn nút OK hay CancelJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
- Nếu kết quả là
041, Dòng 11 in raJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
054. Nếu không, Dòng 13 inJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
055JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
CỐ GẮNG. Thay vì in tin nhắn chúc mừng bằng cách sử dụng
JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
002, hãy thực hiện điều đó thông qua một
JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
001JS phía máy khách EG 3. Đối tượng
JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
058
JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
Tập lệnh sau tạo một đối tượng
JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
058 biểu thị ngày giờ hiện tại và in thời gian hiện tại
JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
3Làm thế nào nó hoạt động?- Dòng 8 khai báo một biến có tên là
060. Nó cũng tạo một đối tượngJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
058 [thông qua toán tửJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
062], chứa dấu ngày-giờ hiện tại và gán nó choJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
060JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
- "______2064" bắt đầu nhận xét cuối dòng [Dòng 8 và 9]. Các nhận xét bị công cụ JavaScript bỏ qua nhưng quan trọng trong việc giải thích mã của bạn cho người khác [và cho chính bạn ba ngày sau]
- Dòng 9 khai báo một biến có tên là
065. Nó cũng gọi hàmJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
066 trên đối tượngJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
060, ở dạngJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
068, để truy xuất phần giờ của đối tượngJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
060 và gán nó cho biếnJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
065. Dòng 9 và 10, tương tự, xử lý phút và giâyJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
- Dòng 12 đến 14 sử dụng
071 để ghi vào tài liệu hiện tại.JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
072 [write-line] viết một dòng mới [JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
073] sau chuỗi đã cho. Hãy lưu ý rằng trình duyệt bỏ qua khoảng trắng thừa [dòng mới, khoảng trống, tab] trong tài liệu HTML;JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
- Dòng 16-20 chứa câu lệnh if-then-else có điều kiện. Tùy thuộc vào giá trị của
065, một trong các thông báo sẽ được hiển thịJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
- Sửa đổi tập lệnh trên để in ngày, tháng, năm và ngày hiện tại trong tuần. [Gợi ý. Sử dụng các hàm
077,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
078,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
079 vàJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
080 của đối tượngJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
058.JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
077 trả về 1-31.JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
078 trả về 0 đến 11 cho tháng 1 đến tháng 12.JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
079 trả về một năm có 4 chữ số.JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
080 returns 0 to 6 for Sunday to Saturday]JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
- Sử dụng câu lệnh điều kiện để in ngày trong tuần trong word [i. e. , 0 cho Chủ Nhật, 1 cho Thứ Hai, v.v. ]. [Gợi ý. Sử dụng cấu trúc
086 như sau. ]____111JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
JS phía máy khách EG 4. vòng lặp
The following script prompts the user for a multiplier, and prints the multiples of 1 to 100 using a for-loop
JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
12Làm thế nào nó hoạt động?- Line 11 prompts the user for a number, and assigns it to the variable
087JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
- Dòng 12-14 chứa vòng lặp for. Một vòng lặp for có cú pháp sau.
14JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
Có bốn phần trong vòng lặp for. Ba trong số đó, khởi tạo, kiểm tra và xử lý hậu kỳ, được đặt trong ngoặc đơn
088 và cách nhau bằng 2 dấu chấm phẩy. Phần thân chứa nhiệm vụ lặp đi lặp lại sẽ được thực hiện. Câu lệnh khởi tạo được thực hiện đầu tiên. Bài kiểm tra sau đó được đánh giá. If the test returns true, the body is executed; followed by the post-processing statement. Thử nghiệm được đánh giá lại và quá trình lặp lại cho đến khi thử nghiệm trả về sai. Khi kiểm tra là sai, vòng lặp for hoàn thành và việc thực thi chương trình tiếp tục đến câu lệnh tiếp theo sau vòng lặp for. Lưu đồ sau đây minh họa quy trình vòng lặp for.JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
Trong ví dụ này, biến
089 được khởi tạo thành 1. NếuJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
089 nhỏ hơn hoặc bằng 100, phần thân của vòng lặp sẽ thực thi, theo sau là câu lệnh xử lý hậu kỳ, làm tăng giá trị củaJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
089 lên 1. Vòng lặp lặp lại cho đến khi giá trị củaJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
089 KHÔNG nhỏ hơn hoặc bằng 100 [i. e. , more than 100]JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
- Sửa đổi tập lệnh trên để nhắc người dùng về hệ số nhân cũng như số bội số được in [trong hai câu lệnh
030]JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
- Sửa đổi tập lệnh trên để chỉ in các bội số là số lẻ. [Gợi ý. Toán tử modulo "
094" có thể được sử dụng để tính toán phần còn lại, e. g. ,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
095 tính phần còn lại củaJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
096 chia cho 2, kết quả là 0 hoặc 1. ]JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
JS phía máy khách EG 5. Hàm do người dùng định nghĩa và Trình xử lý sự kiện
JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
097
JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
Besides the JavaScript built-in functions such as
JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
001,
JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
030,
JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
500, and
JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
072, you can define your own functions. Một hàm có tên và phần thân bao gồm một tập hợp các câu lệnh JavaScript cùng thực hiện một nhiệm vụ nhất định. Nó có thể lấy 0 hoặc nhiều đối số từ người gọi và trả lại 0 hoặc một giá trị cho người gọi
JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
29Làm thế nào nó hoạt động?- Các dòng 8-10 định nghĩa một hàm có tên là
502, thông qua từ khóaJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
503. Hàm gọi hàm tích hợp sẵnJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
504, hàm này sẽ mở một cửa sổ [hoặc tab] trình duyệt mới và tải trang "_______6505"JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
- Dòng 15-16 tạo nút HTML. Nhấp vào nút sẽ kích hoạt trình xử lý sự kiện
097, tôi. e. ,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
502 được xác định trước đóJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
CỐ GẮNG. Bao gồm một nút khác, mở ra "______6508"
JS phía máy khách EG 6. More Event Handlers.
JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
509,
JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
510 and
JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
511
JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
JavaScript can be used to handle many types of events, in response to a user's action or browser's action. For example,
509. fires after browser loaded the pageJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
510 andJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
511. fires when the user points the mouse pointer at/away from the HTML elementJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
Dissecting the Program- Line 8 defines a variable
515, which holds the strings to be displayed in theJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
509 event handlersJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
- In the opening tag [Line 12], we define the
509 event handler for theJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
518 event. It invokesJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
001 with the message defined earlierJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
- Line 13 and 14 defines the event handlers
510 andJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
511 for the HTML elementJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
The text's color will be changed to red when the user points the mouse pointer at the element [by setting the CSS style property
522 to red], and revert back to its original color when the mouse pointer is moved away [by resetting the CSS style propertyJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
522 to an empty string]. The special keywordJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
524 refer to this objectJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
Client-Side JS EG 7. Tách HTML, CSS và JavaScript
The previous example works fine. You will find many such example in textbooks, especially the older textbooks. However, it has a big problem. All the HTML contents, CSS presentation styles and JavaScript programming codes are placed in a single file. For a small toy program, the problem is not serious. But when your program grows and if the HTML, CSS and JavaScript are written by different people, you will have a real challenge in maintaining the program. Remember that HTML is for the contents, CSS for presentation and JavaScript for the behavior
Let's rewrite the example to place the HTML, CSS and JavaScript in three different files
JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
0
JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
00
JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
01Làm thế nào nó hoạt động?- Placing the scripting codes inside the HTML page is not a good software engineering practice. Instead, the now-preferred approach is to place the scripts, as well as CSS styles, in external files, which can then uniformly applied to all pages in your website
- Let's begin with the HTML file. Now, the HTML file keeps only the contents, no presentation style and nor programming logic
The CSS style sheet is kept in an external file, referenced via the above
009 tag.JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
Note. In HTML4/XHTML1. 0 bạn cần đưa thuộc tính
526 vào thẻ mởJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
009.JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
Also, the JavaScript programming code is kept in an external file, referenced via the above
009 is needed, although there is no content.JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
Note. In HTML4/XHTML1. 0, you need to include attribute
010 in theJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
009JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
02How it works?JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
- This HTML document contains a element with an unique
531 [Line 10], twoJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
elements [Line 11-12], three
các phần tử có
532 [Dòng 13-15] và ba phần tửJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
009 với duy nhất làJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
534 [Dòng 16-18]JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
- Trong hàm do người dùng định nghĩa
535, chúng tôi sử dụngJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
536 để chọn phần tử, sau đó sửa đổi thuộc tínhJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
537 của nóJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
- Trong hàm
538, chúng tôi sử dụngJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
539 để chọn tất cảJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
các phần tử trong một mảng
540. Sau đó, chúng tôi sử dụng vòng lặp for để lặp qua tất cả các phần tử trong mảng. Thuộc tínhJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
541 giữ độ dài của mảngJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
- Trong chức năng
542, chúng tôi sử dụngJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
543 để chọn tất cảJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
elements
- The page contains three buttons to trigger the functions defined [Line 16-18]
- The script contains a function
544, which is assigned as theJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
509 handler viaJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
546. That is,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
544 will be triggered after the page is loaded. TheJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
544 function assignsJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
097 event handlers to the buttons, selected viaJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
550 using the unique buttons'JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
534JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
TRY. [TODO]
JS phía máy khách EG 9. Intercepting a Hyperlink
This example uses a script to intercept a hyperlink to put up a warning message, then proceed to the link
03JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
04How it works?JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
- Trang HTML có một siêu liên kết ________ 2009 với một ________ 6534 duy nhất
- The
544 function assigns anJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
097 handler to the hyperlink, selected viaJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
550JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
- Khi nhấp vào siêu liên kết, trình xử lý
097JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
558 được kích hoạt. IfJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
031 returns true, the new page will be loaded; otherwise, the current page remainsJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
TRY. [TODO]
Các ví dụ JavaScript nâng cao khác
More "Advanced JavaScript Examples"
Debugging JavaScripts
Một trình gỡ lỗi đồ họa là PHẢI trong lập trình. Đặc biệt, lập trình bằng JavaScript yêu cầu một trình sửa lỗi tốt. It is because JavaScripts are interpreted and does not need to be compiled. Hence, there is no compiler to show you the syntax errors. A simple and trivial syntax error [e. g. , missing bracket, mis-spelling] will render the entire script not workable. Worst still, you would not see any error message when the script did not work. Can you debug without any error message or clue?
Without a graphic debugging, the only mean to debug JavaScript is to insert
001 at strategic locations to print out selected dataJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
After modifying a JavaScript, I recommend that you use Ctrl-F5 to refresh the page, which shall load a fresh copy instead of loading from the cache. You might need to clear the browser's cache or re-start the browser, if you modification does not take effect
Công cụ dành cho nhà phát triển web F12In Chrome and Firefox, you can press F12 to activate the developer Tools [hence called F12 Developer Tools]
It provides these features
- Console. View the JavaScript error messages. Start the firebug and switch to the "Console" panel
- Kịch bản. Xem và gỡ lỗi JavaScript. Bắt đầu con bọ lửa. Chuyển sang bảng "Script". "Bật" hoặc "Tải lại" nếu cần. You can set a breakpoint by clicking on the statement number, single step through the JavaScript statements, watch the expression, and etc
- DOM. View the HTML DOM of the current document
- HTML and CSS
To debug JavaScript
- Launch Firebug ⇒ Choose the "Script" panel to view your JavaScript, shown with green-bold line numbers
- Làm mới [Ctrl-F5] trang và kiểm tra bảng điều khiển lỗi [Trong "Bảng điều khiển" ⇒ "Lỗi"] để biết các lỗi cú pháp. Sửa tất cả các lỗi cú pháp
- Để theo dõi chương trình, hãy đặt các điểm dừng tại các câu lệnh JavaScript đã chọn, bằng cách nhấp vào lề phải [ở bên trái của số dòng]. A red circle shows up denoting a breakpoint. Take note that you can only set breakpoint on statements with a green-bold line number. [Nếu các câu lệnh JavaScript của bạn không có số dòng in đậm màu xanh lá cây, thì có lỗi cú pháp trên các câu lệnh này. You need to correct the syntax errors and reload the page. ]
- Trigger the script [via clicking button/link, or reloading the page]. The execution stops at the first breakpoint. You can then step-over the statement [or step-into function], and inspect the variables by positioning the mouse pointer on the variable; or add the variable to "watch"
- You can resume the execution [via the continue button]
561JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
Thay vì sử dụng
001 vàJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
002 để hiển thị kết quả trung gian, bạn cũng có thể sử dụngJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
564, viếtJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
565 và giá trị củaJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
566 vào bảng điều khiển lỗi. Nó không can thiệp vào sự xuất hiện của trang web cũng như hoạt động bình thường của bạnJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
Ví dụ: sửa đổi JavaScript trong Ví dụ 8 để in các giá trị của InternalHTML trước khi sửa đổi. Bạn cần bật bàn điều khiển [nhấn F12] để xem đầu ra
05JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
JavaScript và HTML
Như đã thấy từ các ví dụ trước, JavaScript được nhúng bên trong tài liệu HTML và được trình duyệt thực thi. Có hai trường hợp mà trình duyệt thực thi các lệnh JavaScript
- JavaScript đính kèm trong
009 chạy trong khi tải trangJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
- Một số JavaScript, được gọi là trình xử lý sự kiện, chạy do hành động [hoặc sự kiện] của người dùng hoặc trình duyệt. Ví dụ: nhấp vào nút [
097] hoặc tải trang [JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
509]JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
Do đó, có hai nơi để đặt JavaScript của bạn
- giữa các thẻ vùng chứa
009;JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
- bên trong các thẻ HTML dưới dạng trình xử lý sự kiện [chẳng hạn như
097,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
510,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
509], e. g. ,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
574JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
009 chứa các câu lệnh lập trình JavaScript. Ví dụ,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
Trong HTML4/XHTML1. 0, bạn cần bao gồm thuộc tính
576 trongJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
009 là cần thiết mặc dù không có nội dung. ?JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
Trong HTML4/XHTML1. 0, bạn cần bao gồm
576 trong các thẻJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
009 và chạy nó dưới trình duyệt web, bạn sẽ cần kích hoạt trình gỡ lỗi [Công cụ dành cho nhà phát triển web] để xem kết quả. Xem phần trên về các ví dụ phía máy kháchJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
JS độc lập Ví dụ 2. [LÀM]- This HTML document contains a element with an unique
- Nhận xét HTML được đính kèm bên trong
- CSS hỗ trợ chú thích nhiều dòng
583, nhưng KHÔNG hỗ trợ chú thích cuối dòngJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
064JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
- JavaScript hỗ trợ cả
583 vàJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
064, như Java/C/C++/C#JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
- An identifier can contain letters [
301,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
302], digits [JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
303], underscore [JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
304] and dollar sign [JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
305]. Nhưng nó không thể bắt đầu bằng một chữ số [JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
303]JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
- Mã định danh phân biệt chữ hoa chữ thường. Một
003 KHÔNG phải là mộtJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
005, và KHÔNG phải là mộtJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
004JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
- Mã định danh không thể là từ khóa
- Hãy lưu ý rằng KHÔNG được phép có dấu gạch ngang [
310] và khoảng trắng. Do đó,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
311,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
312, KHÔNG phải là định danh hợp lệ. Bạn nên sử dụng dấu gạch dưới [JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
304] thay vì dấu gạch ngang [JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
310]JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
- chuỗi. một dãy ký tự. Các chuỗi ký tự được đặt trong một cặp dấu nháy đơn hoặc nháy kép [e. g. ,
317,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
320]JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
- con số. lấy cả hai số nguyên [e. g. ,
315] hoặc dấu phẩy động [e. g. ,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
322]JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
- boolean. lấy nghĩa đen boolean của một trong hai
041 hoặcJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
042 [viết thường]JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
- không xác định. nhận một giá trị theo nghĩa đen đặc biệt được gọi là
325. Hãy lưu ý rằngJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
325 vừa là loại vừa là giá trị theo nghĩa đenJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
- Biểu tượng. mới trong ECMAScript 6. Một kiểu dữ liệu có thể hiện là duy nhất và không thay đổi
- vật. cho các đối tượng chung
- chức năng. cho các đối tượng chức năng. Không giống như Java, hàm là một đối tượng hạng nhất trong JavaScript, e. g. , bạn có thể gán một hàm cho một biến
- vô giá trị. Một giá trị theo nghĩa đen đặc biệt cho chưa phân bổ [chưa được xây dựng]
327JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
- Số thập phân. bắt đầu bằng chữ số
347 đếnJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
348 [không phảiJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
349], e. g. ,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
350 hoặcJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
351,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
- bát phân. bắt đầu bằng một chữ số
349, e. g. ,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
353 hoặcJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
354,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
- thập lục phân. bắt đầu bằng
355 [hoặcJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
356], e. g. ,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
357 hoặcJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
358JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
- nhị phân. bắt đầu bằng
359 [hoặcJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
360], e. g. ,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
361 hoặcJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
362. [Nhị phân có thể không được hỗ trợ trong một số trình duyệt. ]JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
- vô cực. e. g. ,
367JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
- -vô cực. e. g. ,
368JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
- NaN [Không phải là số]. e. g. ,
369 hoặc chuyển đổi chuỗiJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
370 thành một sốJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
- parseInt[str], parseFloat[str]. Phân tích cú pháp
016 cho đến chữ số đầu tiên và trả về số;JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
- môn Toán. vòng[số], Toán. sàn[số], Toán. trần nhà [số]
- môn Toán. ngẫu nhiên[]. Tạo một số ngẫu nhiên giữa 0 [bao gồm] và 1 [độc quyền]
- isNaN[str]. trả về true nếu
016 không phải là số. Ví dụ,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
07Thật thú vị khi lưu ý rằng JavaScript không có các chức năng đối ứng nhưJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
393,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
394JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
- Số[str]. Trả về số đại diện bởi
040, hoặcJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
391. Cho rằng tên hàm này bắt đầu bằng chữ hoa, bởi vì đây là thao tác truyền kiểuJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
- toFixed[decimalPlaces]. Trả lại số/chuỗi này về số vị trí thập phân đã cho. Ví dụ,
08JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
- chiều dài. e. g. ,
1140 trả về độ dài của chuỗiJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
- Đến trường hợp trên[]. trả về chuỗi chữ hoa
- toLowerCase[]. trả về chuỗi chữ thường
- charAt[idx]. trả về ký tự ở vị trí
1141. Chỉ số bắt đầu từ 0. Có thể sử dụng chỉ mục phủ định, tính từ cuối chuỗiJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
- chuỗi con [bắt đầuIdx, endIdx]. trả về chuỗi con từ
1142 [bao gồm] đếnJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
1143 [độc quyền]JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
- chất nền [bắt đầuIdx, chiều dài]. trả về chuỗi con từ
1142 củaJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
1145JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
- indexOf[searchStr, fromIdx?]. Trả về chỉ mục bắt đầu của lần xuất hiện đầu tiên của
1146, bắt đầu từ một tùy chọnJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
1147 [mặc định là 0];JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
- lastIndexOf[searchStr, fromIdx?]. Trả về chỉ mục bắt đầu của lần xuất hiện cuối cùng của
1146JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
009, bắt đầu từ một tùy chọnJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
1147 [mặc định làJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
1152];JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
- lát cắt [bắt đầuIdx, endIdx]. Trả về chuỗi con từ
1154 [bao gồm] đếnJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
1155 [không bao gồm]JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
- tách [dấu phân cách]. trả về một mảng bằng cách tách chuỗi bằng cách sử dụng
1156JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
- Tìm kiếm/Sửa đổi chuỗi bằng biểu thức chính quy. Xem "Biểu thức chính quy"
- số
349JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
- số
391 [Không phải là số],JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
- chuỗi rỗng [
1113,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
1178],JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
- Giá trị
325,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
- boolean
042,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
- Đối tượng
036 [chưa phân bổ]JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
- Khi một số được so sánh với một chuỗi, chuỗi đó được chuyển đổi thành một số [hoặc
391 nếu nó không chứa một số hợp lệ]. Do đó,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
1204 trả vềJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
041. Nhưng,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
1206 trả vềJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
042, vì toán hạng không cùng kiểuJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
1197,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
1209,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
1198,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
1211 có thể được áp dụng cho boolean [và tất cả các loại JavaScript], e. g. ,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
1212 choJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
041 [vì chuỗi rỗng được chuyển thànhJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
042];JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
- KHUYẾN NGHỊ sử dụng
1197 [hoặcJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
1209], thay vìJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
1198 [hoặcJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
1211], trừ khi bạn chắc chắn rằng loại đó không quan trọngJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
- ngắt - thoát khỏi vòng lặp trong cùng
- tiếp tục - hủy bỏ lần lặp hiện tại và tiếp tục với lần lặp tiếp theo
- nhãn mác. - cung cấp mã định danh cho câu lệnh, có thể được sử dụng bởi
1266 vàJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
1267JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
- Sử dụng chỉ mục
1289 để thêm một mục vào cuối mảngJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
- Sử dụng
1280 để xóa một chỉ mục cụ thể [đặt thànhJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
325]JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
- Sử dụng
1292 để thêm một hoặc nhiều mục vào cuối mảng.JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
1293 trả về độ dài kết quả của mảngJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
- Sử dụng
1294 để thêm một hoặc nhiều mục vào đầu mảng.JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
1295 trả về độ dài kết quả của mảngJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
- Sử dụng
1296 để xóa và trả về phần tử cuối cùng của một mảngJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
- Sử dụng
1297 để xóa và trả về mục đầu tiên của một mảngJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
- chiều dài. số lượng mặt hàng bao gồm
325 mặt hàng. Trên thực tế,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
1278 được đặt thành chỉ số cuối cùng cộng với 1JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
- mảng. tham gia [[dấu phân cách]]. nối các phần tử của một mảng lại với nhau thành một chuỗi duy nhất, được phân tách bằng ____11408 [mặc định là ____11409]. Ví dụ, ______1116
- str. split[[dấu phân cách, giới hạn]]. Đảo ngược của
1410. Lấy một chuỗi và chia thành một mảng dựa trênJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
1411. Ví dụ,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
- mảng. concat[giá trị1, giá trị2,. , giá trịN]. trả về một mảng mới bao gồm mảng này và các mảng hoặc giá trị đã cho. Ví dụ, ______1117
- mảng. đảo ngược[]. đảo ngược thứ tự các phần tử trong mảng, phần tử đầu tiên trở thành phần tử cuối cùng. Ví dụ, ______1118
- mảng. loại[]. sắp xếp các phần tử trong mảng. Ví dụ, Take note take, theo mặc định, số cũng được sắp xếp dựa trên thứ tự ASCII/Unicode. Để sắp xếp các số theo số, bạn có thể cung cấp chức năng so sánh gọi lại. Hàm sẽ nhận 2 đối số, chẳng hạn như
1412 vàJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
1413, đồng thời trả về một số âm nếuJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
1414;JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
- mảng. lát cắt [bắt đầuIdx, endIdx]. trích xuất và trả về một phần của mảng từ
1154 [bao gồm] đếnJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
1155 [độc quyền]. Ví dụ, ______1119JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
- mảng. mối nối [startIdx, CountToRemove, insertItem1, insertItem2,. ]. loại bỏ các phần tử khỏi một mảng và chèn các phần tử vào vị trí của nó. Ví dụ,
- mảng. indexOf[searchItem[, startIdx]] và mảng. lastIndexOf[searchItem[, startIdx]]. tìm kiếm chỉ mục của mục tiến hoặc lùi. Nó trả về -1 nếu không tìm thấy mục. Ví dụ,
- đẩy[]. thêm một hoặc nhiều phần tử vào cuối một mảng và trả về độ dài kết quả của mảng
- nhạc pop[]. loại bỏ và trả về phần tử cuối cùng từ một mảng
- sự thay đổi[]. loại bỏ và trả về phần tử đầu tiên từ một mảng
- bỏ dịch []. thêm một hoặc nhiều phần tử vào phía trước của một mảng và trả về độ dài kết quả của mảng
- mảng. forEach[gọi lại]. nhận một hàm với một đối số lặp qua tất cả các mục trong mảng.
120LƯU Ý. Cú pháp này nhằm hỗ trợ lập trình chức năng của mẫu filter-map-reduceJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
- mảng. bản đồ [gọi lại]. trả về một mảng mới, chứa tất cả giá trị trả về từ việc thực thi
1419 trên mỗi mục. Ví dụ,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
- bộ lọc [gọi lại]. trả về một mảng mới, chứa các mục mà
1419 đã trả về choJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
041. Ví dụ,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
- mảng. mọi [gọi lại]. trả lại
041 nếuJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
1419 trả lạiJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
041 cho TẤT CẢ các mặt hàngJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
- mảng. một số [gọi lại]. trả về
041 nếuJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
1419 trả vềJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
041 cho ít nhất một mục trong mảngJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
- when you have to use the same codes several times
- as the JavaScript event handler
- make your program easier to read and understood
- Sử dụng câu lệnh khai báo hàm ở dạng.
126JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
- Use a function expression by assigning an anonymous function to a variable.
127JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
- alert[str]. Pop-up a box to alert user for important information. The user will have to click "OK" to proceed. The
001 returns nothing [orJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
325]JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
- prompt[str, defaultValue]. Pop-up a box to prompt user for input, with an optional
1455. TheJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
030 returns the user's input as a string. For example,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
- confirm[str]. Pop-up a box and ask user to confirm some information. The user will have to click on "OK" or "Cancel" to proceed. The
031 which returns a boolean value. For example,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
- document. write[str], document. writeln[str]. Write the specified string to the current document. The
072 [write-line] writes a newline after the string, whileJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
500 does not. Take note that browsers ignores extra white spaces, including newlines, in an HTML document, and treat newline as a single blank character. You need to write aJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
075 orJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
074 tag to ask the browser to display a line breakJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
- console. log[value]. write to the system [or error] console, used mainly for debugging
- parseInt[str], parseFloat[str]. parses the given
016 and returns the numeric value orJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
391 [Not-A-Number]. TheJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
1464 accepts an optionalJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
1465 [or base]. For example,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
128JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
- Number[object]. returns the number representation of the object. It works for
1466 object, as well as many objects such asJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
058JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
- isFinite[number]. returns
041 ifJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
089 is notJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
391,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
1471 orJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
1472JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
- isNaN[number]. returns
041 if number isJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
391. Useful for checking the output ofJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
377 andJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
1128JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
- đánh giá [mã]. evaluate the given JavaScript codes, which could be an expression or a sequence of statements. For example. [TODO]
- encodeURI[], decodeURI[], encodeURIComponent[], decodeURIComponent[]. encode or decode name-value pairs for the HTTP request, by replacing special characters with
1477. For example. [TODO]JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
1478. generated when the user clicks on an HTML elementJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
1479,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
1480. generated when the user positions the mouse pointer inside/away from the HTML elementJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
518,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
1482. generated after the browser loaded a document, and before the next document is loaded, respectivelyJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
- Thuộc tính [hay còn gọi là biến, thuộc tính]. chứa các giá trị được liên kết với đối tượng
- Phương thức [còn gọi là phép toán, hàm]. chứa các hành động mà đối tượng có thể thực hiện
- A JavaScript object is a collection of properties. Each property is an association of a name [key] and value pair
- The name and value are separated by a colon
1498JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
- The name-value pairs are separated by commas
1409. No comma is needed after the last name-value pairJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
- The property name could be a string or a number. For string name which is NOT a valid identifier [an valid identifier begins with an alphabet, underscore or dollar sign; and does not containing special characters like blank or
2900], you need to enclose the name with single or double quotes. Otherwise, the quotes are optional. For example, Take note that if the property name's string is a proper identifier, you can omit the quotes. This is commonly practiced by the developersJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
- The property value could be a literal, a variable or an expression
- A property's value could take all JavaScript types, including primitives [string, number, boolean], object or function. The property is known as a method, if it holds a function. JavaScript does not differentiate between variables and methods like conventional OO languages [Java/C++/C#]. A method is simply a property holding a function
- Objects created via Object Initializer are instances of class
2901JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
- The dot [
2902] operator. In the form ofJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
2903 orJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
2904, just like Java/C++JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
- The index
2905 operator [or bracket notation]. In JavaScript, you can also use the index operator to access the object properties, in the formJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
2906, just like accessing an array itemJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
- for. in. đi qua tất cả các thuộc tính có thể đếm được của một đối tượng và chuỗi nguyên mẫu của nó
- Vật. keys[obj]. return an array of all enumerable property names
- Object. getOwnPropertyNames[obj]. return an array of all property names
- An undeclared variable has type of
325, and its value cannot be referencedJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
- A declared but uninitialized variable has type of
325, with a special literal value ofJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
325 too. [JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
325 is both a type and a literal value. ]JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
- A unallocated object has a special literal value of
036. Take note thatJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
036 is an objectJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
- toString[]. trả về một chuỗi mô tả về đối tượng này
- valueOf[]. converts this object to a primitive value such as
089JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
- directly assigned a string literal in the form of
2988 orJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
2989 to a variable, resulted in aJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
331 primitiveJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
- invoke the
1466 object constructor to construct aJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
1466 objectJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
19. constructs aJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
058 object with the current date and timeJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
21. xây dựng một đối tượngJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
058 với chuỗi ngày-giờ đã cho ở dạng có thể chấp nhận được [e. g. , "Month, day, year, hours. minutes. seconds"]JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
23. where month is 0-11 for Jan to DecJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
24JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
077,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
26,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
078,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
28,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
079,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
30. lấy/đặt ngày [1-31], tháng [0-11 từ tháng 1 đến tháng 12], năm [năm có 4 chữ số]JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
080. get the day of the week [0-6 for Sunday to Saturday]JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
066,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
33,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
34,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
35,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
36,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
37. get/set the hours/minutes/secondsJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
38,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
39. get/set the number of milliseconds since January 1, 1970, 00. 00. 00JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
41,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
42. Euler’s constant andJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
42JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
44,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
45,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
46,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
47.JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
48,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
49,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
50,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
51JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
52,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
53. căn bậc hai của 2 rưỡiJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
54JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
55,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
56,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
57,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
58,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
59,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
60,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
61JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
62,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
63,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
64JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
65,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
66,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
67,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
68JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
69,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
70JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
71. returns a pseudo-random number between 0 and 1JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
- Every JavaScript object has a prototype. Nguyên mẫu cũng là một đối tượng. Một đối tượng JavaScript được tạo từ một đối tượng nguyên mẫu và nhận các thuộc tính ban đầu của nó từ nguyên mẫu
- Every JavaScript object has an internal property called
89, which holds its prototype object. Khi bạn xác định một đối tượng mới thông qua "Trình khởi tạo đối tượng" [hoặc hàm tạoJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
90], thìJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
89 của nó được đặt thành một đối tượng tích hợp có tên làJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
92. Nói cách khác, đối tượng mới sử dụngJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
92 làm nguyên mẫu và nhận các thuộc tính ban đầu của nó từJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
92. TheJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
89 property is not enumerable, i. e, nó sẽ không hiển thị trong vòng lặpJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
96.JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
For example, - Any object can be the prototype of new objects. For example,
2901 is the prototype ofJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
98;JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
98 is the prototype forJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
85;JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
85 is the prototype forJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
002. These objects form a so-called prototype chain, i. e. ,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
003. Take note thatJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
2901 is always on top of the prototype chain for every JavaScript objectJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
- You can add or remove properties for an object at runtime, which is not permitted in conventional OO languages
- Properties [including methods] are declared inside the constructor via
014, which can then be initializedJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
- Methods can be declared inside the constructor via
015. There are a few ways to provide the method's definitionJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
- Define an ordinary
503, and assign theJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
017 [without parentheses, which is aJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
503 type] toJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
015, as in theJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
013JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
- Assign
015 to an inline function, as in theJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
012JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
- Invoke the
72 constructor withJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
062 operator [rarely-used].JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
145JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
- Define an ordinary
- To invoke a method, use
025JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
- The
2970 is a special method, which returns a string description of this object. TheJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
2970 will be implicitly invoked if an object is passed into theJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
002,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
071 orJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
023 operator [like Java]JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
- Create a new generic object using built-in root
2901 as prototypeJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
- Assign this newly created object to
524 variableJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
- Run the constructor function, which typically adds properties to
524JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
- Đặt thuộc tính bên trong
89 thànhJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
039 [trong ví dụ trên,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
040]. TheJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
89 property is not enumerable [i. e, nó sẽ không hiển thị trong vòng lặpJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
96]. Nó được sử dụng để duy trì cái gọi là "chuỗi nguyên mẫu" của các đối tượngJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
- Return the newly created object
- Check if the property exists locally [i. e. , tài sản riêng]
- Otherwise, check the
89 property. This continues recursively up the prototype chain. The process is called "lookup in the prototype chain"JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
- via built-in functions
091 orJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
092;JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
- inside the "object initializer" via keywords
093 andJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
094JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
- The
097 allows you to define multiple properties; whileJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
098 for a single propertyJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
- You invoke the getters/setters like properties with assignment operator, instead of via function call
- The getter/setter are defined inside Object Initializer via keywords
093 andJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
094 with a rather strange syntax, as shown in the exampleJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
- DOM Level 0 [DOM0] [Pre-W3C]. obsolete
- DOM Level 1 [DOM1] [W3C Oct 1998]. obsolete
- DOM Level 2 [DOM2] [W3C Nov 2000] and DOM Level 2 HTML [HTML DOM2] [W3C Jan 2003]
- DOM Level 3 [DOM3] [W3C Apr 2004]. yet to be fully supported by browsers
0020 returns an array of allJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
0021 elements, same asJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
0022JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
0023. return an array of allelementsJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
0024 andJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
0025. return all the hyperlinksJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
009and anchorsJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
009elements. [To confirm. ]JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
- Document Node. the root node representing the entire HMTL document
- Element node. represents an HTML element [or tag]. An element node may have child nodes, which can be either element or text node. Element node may also have attributes
- Text Node. contains the text content of an element
- Others. such as comment, attribute
0031. contain the name of the node, which is read-only. TheJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
0031 for an Element node is the tag-name;JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
0031 for the Document node isJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
0034;JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
0031 for Text nodes isJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
0036JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
0037. contain the value of the node.JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
0037 cho nút Văn bản là văn bản được chứa;JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
0040. một số nguyên cho biết loại nút, e. g. , Element [1], Attribute [2], Text [3], Comment [8], Document [9]JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
0041. tham chiếu đến nút cha. Chỉ có một nút cha trong cấu trúc câyJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
0042. array [or node-list] of child nodesJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
0043,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
0044. reference to the first and last child nodeJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
0045,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
0046. reference to the previous and next sibling in the same levelJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
- property
0056, whereJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
0057 is the name of the attribute, orJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
- methods
0058 andJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
0059JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
0063. returnsJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
041 if this node has at least one child nodeJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
- Manipulating child node
0065. insert a node before an existing child nodeJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
0066. replace an existing child nodeJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
0067. remove the specified child nodeJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
0068. append the given node as the last childJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
0069JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
0070JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
[TODO] Kiểm tra các Hạn chế như Tệp IO, Mạng, v.v. So sánh với Shell Script và Python script để tự động hóa
Ví dụ JavaScript phía máy chủ
Bạn cũng có thể sử dụng JavaScript để lập trình ứng dụng web phía máy chủ, giống như Java Servlet/JSP, Microsoft ASP, PHP, Python, v.v. Điểm hấp dẫn là bạn có thể sử dụng một ngôn ngữ duy nhất để lập trình cả phía máy khách và phía máy chủ trong ứng dụng web
Xem nút. bài viết js
Cú pháp cơ bản JavaScript
Bình luận
Các nhận xét bị thời gian chạy JavaScript bỏ qua nhưng rất hữu ích trong việc giải thích mã của bạn cho người khác [và cả cho chính bạn ba ngày sau]. Bạn nên sử dụng nhận xét một cách tự do để giải thích hoặc ghi lại mã của mình
Chú thích cuối dòng bắt đầu bằng
064 và kéo dài đến cuối dòng hiện tại. Nhận xét nhiều dòng bắt đầu bằngJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
581 và kéo dài đếnJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
582JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
lưu ý rằng
Khoảng trắng [trống, tab, dòng mới]
Giống như C/C++/Java, JavaScript bỏ qua các khoảng trắng bổ sung [khoảng trống, tab và dòng mới]. I strongly recommend that you use additional whitespaces to format your program to make your code easier to read and understand
Biểu thức
An expression is a combination of variables, literals, operators, and sub-expressions that can be evaluated to produce a single value
Statements, Semicolon and Blocks
A statement is a single programming instruction. Unlike C/C++/Java, where you need to end a statement with a semicolon [
587], in JavaScript the semicolon is optional. Tuy nhiên, nếu thiếu dấu chấm phẩy, bạn cần kết thúc câu lệnh bằng một dòng mới [và công cụ JavaScript sẽ chèn dấu chấm phẩy cho bạn]JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
Semicolons in JavaScript divide the community. Some prefer to use them always, no matter what. Others like to avoid them for brevity. tôi sẽ để nó cho bạn
A block consists of zero or more statements enclosed in a pair of curly braces
588. No semicolon is needed after the closing braceJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
Biến, chữ và loại
Variable declarations [
044,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
0,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
1] and Assignment Operator [JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
592]JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
A variable is a named storage location that holds a value. Prior to ES6, you can only declare a variable using keyword
044. ES6 introduces two new keywords.JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
0 to declare a local block-scope variable, andJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
1 to declare a local block-scope constant; and leaveJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
044 to declare a global variable. Tôi sẽ thảo luận về phạm vi biến trong phần sauJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
You can assign [and re-assign] a value to a variable using the assignment [
592] operator. For example,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
It is strongly recommended to use
1-declaration if the value doesn't change [this ensure that it will not accidentally change]; andJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
0-declaration for local variable [variables shall not live beyond where they are needed]. UseJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
044-declaration only for global variableIdentifiersJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
Mã định danh là tên được đặt để xác định các thực thể [chẳng hạn như biến và hàm]. The rules for valid identifiers are
Một chữ là một giá trị cố định, e. g. ,
315,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
316,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
317,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
041, có thể được gán cho một biến hoặc tạo thành một phần của biểu thứccác loạiJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
JavaScript là hướng đối tượng. Nhưng, Nó hỗ trợ cả các kiểu và đối tượng nguyên thủy
JavaScript hỗ trợ các kiểu nguyên thủy này
JavaScript cũng hỗ trợ các loại đối tượng và giá trị này [chúng ta sẽ thảo luận về đối tượng sau]
Không giống như hầu hết các ngôn ngữ lập trình chung [chẳng hạn như Java/C/C++/C#] là loại mạnh, JavaScript là loại lỏng lẻo [tương tự như hầu hết các ngôn ngữ kịch bản như UNIX Shell Script, Perl, Python]. Bạn không cần phải khai báo rõ ràng loại biến [chẳng hạn như
328 vàJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
329] trong khi khai báo. Loại được quyết định khi một giá trị được gán cho biến đó. Nếu một số được gán, thì biến đó sẽ có kiểuJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
089 và có thể thực hiện các phép toán số như cộng và trừ. Nếu một chuỗi được gán, biến đó sẽ có kiểuJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
331 và có thể thực hiện các thao tác chuỗi như nối chuỗi. Nói cách khác, loại được liên kết với giá trị, thay vì biếnNhà điều hànhJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
332JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
Bạn có thể sử dụng toán tử
332 để kiểm tra loại giá trị hiện tại được gán cho một biếnJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
Một biến không được khai báo [thông qua từ khóa
044] có một loại đặc biệt gọi làJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
325. Bạn không thể tham khảo giá trị của nóJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
Khi một biến được khai báo [thông qua từ khóa
044] mà không gán giá trị ban đầu, nó sẽ nhận loạiJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
325 và giữ một giá trị đặc biệt có tên làJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
325 [JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
341 có lẽ chính xác hơn?. ], ngay sau khi một giá trị được gán, biến sẽ nhận kiểu của giá trị đó. Hành động đặt một giá trị vào một biến đặt kiểu của nó. Bạn có thể thay đổi loại biến bằng cách gán lại giá trị của loại khác. Nói cách khác, loại được liên kết với giá trị, không phải biến. Các loại được chuyển đổi tự động khi cần trong quá trình thực thi [được gọi là kiểu động]JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
Ví dụ như,
[ES6] Hằng số
1-khai báoJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
Bạn có thể tạo một hằng số chỉ đọc, được đặt tên với từ khóa
1 [thay choJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
044]. Ví dụ,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
06JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
Loại
089, Nghĩa đen & Hoạt độngJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
Một biến kiểu
089 chứa một số, có thể là số nguyên hoặc số dấu phẩy độngJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
Chữ số nguyên có thể được biểu thị bằng
Các chữ số dấu phẩy động có thể được biểu diễn ở dạng thông thường [e. g. ,
363] hoặc ký hiệu khoa học, e. g. ,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
364,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
365JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
JavaScript cũng cung cấp một số chữ
089 đặc biệtJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
Các phép toán số học, như được lập bảng dưới đây, có thể được áp dụng cho các số. Các kết quả sau đây thu được với giả định rằng
371,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
372 trước khi phẫu thuậtToán tửMô tảVí dụResult [JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
371,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
372]+Additionz = x + y;z là 7-Phép trừ [hoặc Phủ định đơn thức]z = x - y;z là 3*Phép nhânz = x * y;z là 10/Dung chiaz = . 5%Modulus [Phần còn lại của phép chia]z = x % y;z is 1++Unary Pre- or Post-Incrementy = x++; . y = x; . x=x-1;JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
Same as: y = x; x = x+1; x = x+1; z = x;y is 5; z is 7; x is 7--Unary Pre- or Post-Decrementy = --x; z = x--;
Same as: x = x-1; y = x; z = x; x = x-1;y is 4; z is 4; x is 3**Exponent
[ES7]y ** xTrong JavaScript, các phép toán số học luôn được thực hiện ở dạng dấu phẩy động có độ chính xác kép [KHÔNG phải là số nguyên]. Nghĩa là,
375 choJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
376 [thay vì 0 trong Java/C/C++]. Bạn có thể sử dụng hàm có sẵnJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
377 để cắt bớt một giá trị dấu phẩy động thành một số nguyên, e. g. ,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
378 vàJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
379 choJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
380. Bạn cũng có thể sử dụng các hàm toán học có sẵn nhưJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
381,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
382,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
383 để chuyển đổi số dấu phẩy động thành số nguyênToán tử số mũ [JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
3]JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
ECMAScript 2016 [ES7] giới thiệu toán tử số mũ [
3], bạn có thể viếtJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
386, e. g. ,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
387JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
Trước ES7, bạn phải sử dụng chức năng tích hợp sẵn
388Toán tử số học kiêm toán tử gánJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
Đây là những toán tử tay ngắn để kết hợp hai hoạt động
Toán tử Mô tảVí dụResult+=Bổ sung kiêm Phép gánx += y;Giống như. x = x + y;-=Phép trừ kiêm phép tínhx -= y;Giống như. x = x - y;*=Phép nhân kiêm phép tínhx *= y;Giống như. x = x * y;/=Phép chia kiêm phép tínhx /= y;Giống như. x = x / y;%=Mô-đun kiêm Bài tậpx %= y;Giống như. x = x % y;Một số Chức năng tích hợp sẵn của
389 thường được sử dụngJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
Loại
331, Chữ & Hoạt độngJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
Một
331 là một dãy ký tự được đặt trong một cặp dấu nháy đơn hoặc nháy kép [e. g. ,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
317,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
320,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
1101,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
1102]. Bạn có thể sử dụng một chuỗi thoát để biểu thị các ký tự đặc biệt không in được [chẳng hạn nhưJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
073 cho dòng mới,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
1104 cho tab vàJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
1105 cho ký tự Unicode]; . g. ,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
1106,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
1107,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
1108]JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
Không giống như Java/C/C++, nhưng giống như các thuộc tính của HTML/CSS, bạn có thể sử dụng dấu ngoặc đơn hoặc dấu ngoặc kép cho
331. Điều này rất hữu ích vì bạn có thể sử dụng dấu ngoặc đơn nếuJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
331 chứa dấu ngoặc kép [e. g. ,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
1111JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
1111], mà không sử dụng trình tự thoát vụng về [e. g. ,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
1113]JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
JavaScript là kiểu động và tự động thực hiện chuyển đổi kiểu. Khi giá trị
331 được sử dụng trong các phép toán số học [chẳng hạn như phép trừ hoặc phép nhân], thời gian chạy JavaScript sẽ tự động chuyển đổiJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
331 thànhJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
089 nếu nó đại diện cho mộtJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
089 hợp lệ; . Ví dụ,Toán tửJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
023. Bổ sung hoặc nối?JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
Nếu cả hai toán hạng của toán tử
023 đều làJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
1122, nó sẽ thực hiện phép cộng số thông thường. Tuy nhiên, nếu một [hoặc cả hai] toán hạng làJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
331, thì toán tửJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
023 bị quá tải để thực hiện nối chuỗi. Toán hạng khác sẽ được chuyển đổi thànhJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
331, nếu cần. Ví dụ,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
1126 chuyển đổi.JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
377,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
1128 vàJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
1129JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
Để chuyển đổi một số
331 thành một sốJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
089, bạn có thể sử dụng các hàm tích hợp sẵnJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
377 hoặcJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
1128, hàm này trả về một sốJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
089 nếu chuyển đổi thành công; . Ví dụ,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
Hãy lưu ý rằng
377 hoạt động miễn làJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
331 bắt đầu bằng các chữ số. Nó sẽ phân tích đến chữ số đầu tiên. Ví dụ,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
09JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
Bạn cũng có thể sử dụng hàm
1129 để chuyển đổi đối số đối tượng thành một số đại diện cho giá trị của đối tượng; . Ví dụ,Thuộc tính của chuỗiJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
[ES6] Chuỗi mẫu nhiều dòng và thay thế
Trước ES6, Bạn có thể đặt một chuỗi ký tự bằng cách sử dụng dấu ngoặc đơn hoặc dấu ngoặc kép [e. g. ,
317,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
320,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
1101,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
1102]. Trình tự thoát sẽ được sử dụng cho các ký tự đặc biệt [e. g. ,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
073 cho dòng mới,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
1104 cho tab] và giải quyết xung đột [e. g. ,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
1106,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
1107,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
1108]. Chuỗi nhiều dòng không được hỗ trợJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
ES6 giới thiệu chuỗi mẫu, được phân tách bằng dấu ngoặc kép, ví dụ:
50JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
Không cần thoát trích dẫn đơn hoặc kép bên trong chuỗi mẫu. Nhưng bạn cần sử dụng trình tự thoát cho trích dẫn ngược, tôi. e. ,
1166JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
Chuỗi mẫu hỗ trợ chuỗi nhiều dòng. Tất cả các khoảng trắng [trống, tab, dòng mới] trong dấu ngoặc kép là một phần của chuỗi nhiều dòng. Ví dụ,
51JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
Hỗ trợ thay thế chuỗi mẫu, cho phép bạn nhúng bất kỳ biểu thức JavaScript hợp lệ nào như một phần của chuỗi ở dạng
1167, ví dụ:JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
Chuỗi mẫu nhiều dòng có thay thế cung cấp một cách thuận tiện hơn để viết ra đoạn HTML được định dạng. Ví dụ,
52JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
1168 Loại, Chữ & Hoạt độngJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
Một biến kiểu
1168 giữ giá trị làJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
041 hoặc làJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
042.JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
041 vàJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
042 là từ khóa trong JavaScriptJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
Như đã đề cập, JavaScript thực hiện chuyển đổi kiểu tự động nếu cần thiết. Trong quá trình chuyển đổi loại, 6 giá trị sau được chuyển đổi thành
042JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
Tất cả các giá trị khác được chuyển đổi thành
041JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
Bạn cần ghi nhớ điều này.
1183 trả vềJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
041 nếuJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
1185 là một trong 6 giá trị này.JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
349,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
391,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
1113,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
325,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
042 vàJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
036Toán tử so sánh [quan hệ]JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
Các toán tử quan hệ sau, tạo ra kết quả
1168, được định nghĩa trong JavaScript. Kết quả thu được giả sửJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
1193,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
1194Toán tửDescriptionExampleResultJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
[
1193,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
1194]==BằngJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
[về Giá trị]
53JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
54. =Không bằng===Hoàn toàn bằngJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
[về Loại và Giá trị]____655
56. ==Hoàn toàn không bằng>Lớn hơn>=Lớn hơn hoặc bằngJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
1197 so với.JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
1198JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
Toán tử đẳng thức hoàn toàn
1197 trả vềJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
041 nếu cả hai toán hạng có cùng kiểu và cùng giá trị;JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
JavaScript cần cung cấp hai toán tử đẳng thức khác nhau, vì nó là kiểu lỏng lẻo và thực hiện chuyển đổi kiểu tự động trong nhiều tình huống. Ví dụ,
Khi so sánh hai chuỗi, thứ tự mã hóa [bảng ASCII/Unicode] được sử dụng. Do đó, chuỗi
1221 lớn hơn chuỗiJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
1222JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
Ví dụ,
Toán tử logic [Boolean]Các toán tử boolean [hoặc logic] sau đây được cung cấp trong JavaScript
Toán tửMô tảVí dụKết quả&&Logical AND. logic HOẶC. Logic NOT&&=Logical AND kiêm gán [ES12]. =Logical OR kiêm nhiệm vụ [ES12]ghi chú.
1223 trong JavaScript là toán tử XOR bitwise, không thực sự là XOR boolean [hiếm khi cần thiết]Đánh giá ngắn mạch cho các biểu thức BooleanJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
Đánh giá các hoạt động logic luôn bị ngắn mạch. Nghĩa là, hoạt động kết thúc ngay khi kết quả là chắc chắn, e. g. , [
1224] bị ngắn mạch để cung cấp choJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
042, [JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
1226] choJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
041,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
8 sẽ không được đánh giáJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
Chuyển đổi loại rõ ràng
Thời gian chạy JavaScript tự động thực hiện chuyển đổi loại. Tuy nhiên, đôi khi, bạn có thể cần chuyển đổi từ loại này sang loại khác một cách rõ ràng
Chuyển đổi một
089 thành mộtJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
331. Đơn giản chỉ cần nốiJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
089 với mộtJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
1232 trống, e. g. ,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
1233 mang lại choJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
1234JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
Chuyển đổi một
331 thành mộtJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
089. Sử dụng các hàm tích hợp sẵnJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
1237,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
1238 hoặcJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
1239 để chuyển đổi mộtJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
016 có chứa mộtJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
089 hợp lệ. Ví dụ:JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
1242 choJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
380,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
378 cho ____JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
Chuyển đổi số float thành số nguyên. Sử dụng
377 [e. g. ,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
378 choJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
380] hoặc các hàm toán học tích hợp nhưJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
381,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
383 hoặcJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
382JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
Kiểm soát luồng - Quyết định [Có điều kiện]
JavaScript cung cấp các cấu trúc điều khiển luồng này. Cú pháp giống như Java/C/C++
Cú phápVí dụ_______657_______658____659____830
31JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
32JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
33JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
34JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
35[ES12] Toán tử gán giá trị rỗng logic [JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
08]JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
Phép gán nullish logic
1261 chỉ gán nếu x làJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
036 hoặcJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
325 [i. e. vô giá trị]. Ví dụ,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
Kiểm soát luồng - Vòng lặp [Lặp lại]
JavaScript cung cấp các cấu trúc vòng lặp sau. Cú pháp giống như Java/C/C++
Cú phápVí dụ____836
37JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
38JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
1264,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
1265 và nhãnJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
Các câu lệnh điều khiển vòng lặp sau được cung cấp [cùng cú pháp với Java/C/C++]
Cố gắng tránh những tuyên bố này, vì chúng khó theo dõi và duy trì
Mảng
Một mảng là một bộ sưu tập được lập chỉ mục. Một mảng có thể được sử dụng để lưu trữ danh sách các mục [phần tử] dưới một tên duy nhất với chỉ số nguyên đang chạy. Bạn có thể tham chiếu phần tử riêng lẻ thông qua chỉ mục tích phân ở dạng
1268. Hơn nữa, bạn có thể xử lý tất cả các phần tử của một mảng một cách thuận tiện thông qua một vòng lặp có chỉ số thay đổiTạo một mảng thông qua "Trình khởi tạo mảngJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
1269"JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
Bạn có thể tạo một mảng bằng cách gán một ký tự mảng cho một biến, được gọi là Trình khởi tạo mảng, ở dạng
1269. Ví dụ như,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
Hãy lưu ý rằng mảng chữ của JavaScript được đặt trong dấu ngoặc vuông
1271, thay vìJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
1272 trong Java/C/C++. JavaScript sử dụngJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
1272 cho đối tượng theo nghĩa đen [sẽ được thảo luận sau]JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
Bạn cũng có thể sử dụng Trình khởi tạo mảng để tạo một mảng có chỉ mục bị thiếu. Ví dụ,
39Truy cập một mụcJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
Bạn có thể truy cập phần tử riêng lẻ của mảng thông qua chỉ mục tích phân, ở dạng
1268. Chỉ số của mảng bắt đầu từ 0 và phải là một số nguyên không âmMảng củaJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
1275JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
Độ dài của mảng được duy trì trong một biến có tên là
1275, có thể được truy cập thông quaJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
1277. Trên thực tế, thuộc tínhJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
1278 trả về chỉ mục tích phân cuối cùng cộng với 1, vì chỉ mục mảng của JavaScript dựa trên 0. Tuy nhiên, bạn được phép thao tác [viết]JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
1278. Ví dụ,Mảng độngJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
Không giống như Java/C/C++, mảng JavaScript được cấp phát động. Bạn có thể thêm nhiều phần tử vào một mảng. Bạn cũng có thể xóa nội dung của một phần tử bằng từ khóa
1280. Ví dụ như,Truy cập tất cả các mục bằng vòng lặp for với chỉ mụcJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
Mảng thường được xử lý chung bằng cách sử dụng một vòng lặp, e. g. ,
110Vòng lặpJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
1281 của JavaScriptJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
JavaScript cung cấp một vòng lặp
1282 đặc biệt để xử lý tất cả các phần tử trong một mảng. Cú pháp như sau, trong đóJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
1283 đảm nhận từng số chỉ mục của phần tử không phải làJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
325JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
111JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
Ví dụ,
Vòng lặp
1285 của JavaScriptJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
JavaScript cung cấp một vòng lặp
1286 đặc biệt để xử lý tất cả các phần tử trong một mảng. Cú pháp như sau, trong đóJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
1287 đảm nhận từng phần tử bao gồm cảJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
325JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
112Thêm/Xóa [các] mụcJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
Bạn có thể
Ví dụ như,
Mục đíchVí dụThêm một mục vào cuối mảng bằng cách sử dụng chỉ mục
1298JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
113Thêm một hoặc các mục vào cuối mảng bằng cách sử dụngJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
1292.JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
______11293 trả về độ dài kết quả của mảng. Thêm một hoặc các mục vào đầu mảng bằng cách sử dụng
1294.JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
______11295 trả về độ dài kết quả của mảng. Xóa và trả lại mục cuối cùng khỏi một mảng bằng cách sử dụng
1296JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
114Xóa và trả lại mục đầu tiên của một mảng bằng cách sử dụngJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
1297JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
115Thuộc tính của mảng [Biến] và Hoạt động [Hàm]JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
Đối tượng
1405 có các thuộc tính thường được sử dụng nàyJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
Nó có những phương pháp thường được sử dụng
Mảng cũng hỗ trợ các phương thức lặp này lặp qua từng mục của mảng, để hỗ trợ lập trình chức năng của mẫu giảm bản đồ bộ lọc
Để biết thông số kỹ thuật chi tiết và các ví dụ về một đối tượng tích hợp sẵn, hãy kiểm tra "Tham khảo JavaScript chính"
Mảng kết hợp của các cặp khóa-giá trị
Một mảng kết hợp là một mảng của cặp khóa-giá trị. Thay vì sử dụng các số 0, 1, 2,. làm khóa như trong mảng thông thường, bạn có thể sử dụng bất kỳ thứ gì làm khóa trong mảng kết hợp. Mảng kết hợp được sử dụng rộng rãi trong JavaScript và jQuery
JavaScript không hỗ trợ mảng kết hợp gốc [nó thực sự cũng không hỗ trợ mảng gốc]. In JavaScript, associative arrays [and arrays] are implemented as objects [to be elaborate later]
You can create an associative array via the Object Initializer. For example,
Take note that Array initializer uses square brackets
1428; while object initializer [for associative array] uses curly bracketsJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
1429JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
Functions
Functions are useful
A function accepts zero or more arguments from the caller, performs the operations defined in the body, and returns zero or a single result to the caller
Functions are objects in JavaScript [to be discussed later]
The syntax for user-defined function is
121JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
Functions are declared using the keyword
503. Unlike Java/C/C++, you do not have to specify the return-type and the types of the arguments because JavaScript is loosely typed. You can use aJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
1431 statement to return a single piece of result to the caller anywhere inside the function body. If noJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
1431 statement is used [or aJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
1431 with no value], JavaScript returnsJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
325JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
For client-side JavaScript, functions are generally defined in the
012 section, so that it is always loaded before being invokedJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
To invoke a function
122Client-Side JavaScript Function ExamplesJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
123Function'sJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
1436JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
Function has access to an additional built-in variable called
1436 inside its body, which is an array containing all the arguments. For example,Pass by Value vs. Vượt qua tham khảoJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
In JavaScript, primitive arguments are passed by value. That is, a copy of the variable is made and passed into the function. On the other hand, objects [including array and associative array] are passed by references. That is, if you modify the content of an object inside the function, the "copy" outside the function is also affected
The Default Function ArgumentsJavaScript lets you invoke a function omitting some trailing arguments. It sets the omitted arguments to the value
325. For example,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
You can use this feature to provide default value to function argument, for example,
In the above example, we allow caller to omit the trailing arguments [
1439,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
1440] or pass aJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
036 value [which is a special literal for unallocated object]JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
The common idiom in practice today is to use the short-circuited OR expression [as in
1440] to provide default value if no value [JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
325 orJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
036] is passed, provided the valid inputs cannot beJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
042,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
349,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
1178, andJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
391 that evaluate toJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
042[ES6] Function with Default Parameter ValuesJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
ES6 greatly simplify the above by introducing default parameter value in the form of
1450. For example,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
124[ES6] Rest/Spread Operator [JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
8] and Arrow-Function NotationJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
ES6 also introduces rest/spread operator [
8] and arrow-function notation. See ES6 articleAnonymous [Inline] FunctionsJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
In JavaScript, you can define an anonymous function [without a function name] using the following syntax
125JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
Anonymous function is often used in event handlers and others
Function VariablesIn JavaScript, a variable can hold a primitive [number, string, boolean] or an object
In JavaScript, functions are first-class object. Do đó, một biến cũng có thể chứa một đối tượng hàm. Ví dụ,
Hai cách trong việc xác định một chức năngAs seen in the above example, there are two ways to define a function
Recall that a function takes zero or more arguments from the caller. In JavaScript, arguments can be a primitive or object. Since functions are first-class objects in JavaScript, a function may take another function as its argument
Ví dụ: hàm sau lấy một hàm và một mảng làm đối số của nó và áp dụng hàm cho mảng
Nested FunctionsIn JavaScript, you can define a function inside a function. For example,
Function as the return valueYou can return a function from a function. For example,
Interacting with Users
Client-side JavaScript provides these built-in top-level functions for interacting with the user
The following top-level built-in functions are available to client-side as well as server-side [or standalone]
Other Top-level Built-in Functions
JavaScript also pre-defines the following top-level global functions
An Introduction to Events [for Client-side JavaScript]
Client-side JavaScript are often event-driven. That is, a function [called event handler] will be fired in response to a certain user's or browser's action that generates an event
The commonly-used events are
The event handler, called
1483 [such asJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
097,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
1485,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
509], is the function that responses to an event. The event handler is typically attached to the target HTML tag, e. g. ,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
129JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
More about events in the later sections
Objects
Objects are Everywhere
JavaScript is object-oriented [OO], and objects are everywhere in JavaScript. Arrays are objects. Functions are also objects. Primitives like string and number are auto-box to objects in many operations. Hầu hết mọi thứ trong JavaScript đều có thể là một đối tượng, có thể ngoại trừ
325 vàJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
036 [đối tượng]JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
Điều quan trọng là phải hiểu các đối tượng để thành thạo JavaScript, vì chúng ở khắp mọi nơi và chúng được sử dụng rộng rãi trong các trình cắm thêm JavaScript như jQuery, AngularJS, React, v.v.
Tuy nhiên, JavaScript không hỗ trợ tất cả các tính năng OO, để giữ cho ngôn ngữ đơn giản
Thuộc tính và phương thức
Trong các ngôn ngữ lập trình hướng đối tượng thông thường [như Java/C++/C#], một đối tượng là một tập hợp các thuộc tính và phương thức dưới một tên chung
Ví dụ: một đối tượng
1489 có các thuộc tính nhưJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
1490,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
1491,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
1492,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
1493;JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
Không giống như các ngôn ngữ OO chính thức, JavaScript được thiết kế trên mô hình OO đơn giản. A JavaScript object is simply a collection of properties. A property is an association between a name [or key] and value [i. e. , cặp tên-giá trị hoặc cặp khóa-giá trị]. If the value is a function [recall that functions are first-class objects that can be assigned to a variable], the property is known as a method. In other words, JavaScript does not differentiate between properties and methods like conventional OO languages. A method is simply a property holding a function
Creating Objects via Object Initializer
You can create a new object by directly assign an object literal to a variable, known as Object Initializer. The syntax is as follows
140JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
Trailing commas [sometimes called "final commas"] can be useful when adding new elements, parameters, or properties to JavaScript code. If you want to add a new property, you can add a new line without modifying the previously last line if that line already uses a trailing comma. This makes version-control diffs cleaner and editing code might be less troublesome. JavaScript has allowed trailing commas in array literals since the beginning, and later added them to object literals [ES?], and more recently, to function parameters [ES?] and to named imports and named exports [ES?]
Property Accessors. The Dot and Index [Square Bracket] operatorIn JavaScript, you can access an object's properties via either
1280 operatorJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
You can remove a property [including method] via "
2908"OperatorJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
2909JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
You can use the
2909 operator to check if a particular instance belongs to a particular class of objects, e. g. ,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
141TheJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
2911 methodJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
The
2912 returnsJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
041 ifJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
2914 has the specificJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
2915OperatorJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
2916JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
You can use the
2916 operator to check if a particular property belongs to an object, for example,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
142Example 1. A Simple ObjectExample 2. An object having object propertiesJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
An object's property can hold primitives [number, string]. It can also hold an object
Example 3. An object with functionA JavaScript object's property can also hold a function [or method]. You can assign to an anonymous function or a named function as shown in the following example
To quote or not to quote the name in name-value pair?The
2918 [of theJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
2919 pair] can take a string or a number, e. g. ,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
2920JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
Many developers do not enquote the string
2918, if it is a valid identifier [a valid identifier begins with an alphabet,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
2922 orJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
2923; and does not contain special characters like blank andJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
2900]. For example,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
2925 is the same asJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
2926. Tuy nhiên, bạn cần trích dẫn một chuỗiJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
2918 nếu nó KHÔNG phải là một mã định danh hợp lệ, e. g. ,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
2928JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
The string
1185 must be enquoted; otherwise, it will be treated as a variable nameDot Operator vs. Index [Square Bracket] OperatorJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
You can access an object's property via either dot operator or index operator. Dot operator is commonly used as it is more concise and used in conventional OO languages. But index operator allows access to properties containing special characters and selection of properties using variables, which is not feasible with dot operator. For example,
Iterate through all the properties of an ObjectThere are three ways to iterate through all properties of an object
Ví dụ,
Operator
2930JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
Establishes the default object for a set of statements. The syntax is
143TheJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
036 vsJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
325 Literal ValuesJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
As discussed earlier
In boolean expressions, both the
036 andJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
325 evaluate toJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
042 [together with empty-stringJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
1113, numberJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
349 andJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
391, and booleanJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
042]. To check forJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
036 value, useJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
2947, asJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
2948 [orJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
1183] returnsJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
041 forJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
036,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
325,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
1113,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
349,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
391, andJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
042JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
Built-in JavaScript Objects
JavaScript provides many useful global objects, such as
1405,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
058,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
1466, andJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
389JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
I shall discuss some commonly used objects here. For detailed specification and examples about a built-in object, check "Core JavaScript References"
Creating an Object via Constructor and the
062 OperatorJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
All the built-in objects define a so-called constructor, which is a special method having the same name as the object, for creating new instances. To invoke the constructor, you need to use a special
062 operatorJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
For example, the
058 object has a constructor method calledJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
2964. To construct a new instance ofJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
058 objectTheJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
332 andJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
2909 OperatorsJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
As seen from the above examples, the
332 operator returns the type of a value, which can be a primitive type [such as number, string, boolean] or object [including function]JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
The
2909 operator check if the value is an instance of a classTheJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
2970 andJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
2971 MethodsJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
The following methods are available to all built-in JavaScript objects
The
1405 Object and Associative ArraysJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
For an introduction to arrays, read the "Arrays" section
Nowadays, we usually create an array via Array Initializer in the form of
1269. Nonetheless, as arrays are objects of classJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
1405, we could also construct an array by invoking theJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
2976 constructor with theJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
062 operator. This is more complex and, hence, less commonly used today [but may show up in old codes and books]JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
Ví dụ,
An Associative Array is a Generic "Object", not an "Array" ObjectFor an introduction to arrays, read the "Associative Arrays" section
JavaScript does not really support associative array, but allow you to add properties to an object, using the associative array syntax and index operator. In other words,
Using an Array Object for Associative ArrayIn JavaScript, we usually create an associative array using a generic object [via the Object Initializer]. You can also create an associative array via
1405 constructor. For examples,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
In this case, additional properties are added into an
1405 object as object's properties. The array hasJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
1278 of 0, asJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
1278 reflects only the numerical indexes. Using an array object for associative array is not recommended. I describe here for completenessJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
The
1466 Object vsJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
331 Primitive TypeJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
JavaScript provides primitive
331 type. It also provide aJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
1466 class as a wrapper class for primitiveJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
331. Read "The string Type, Literals and Operations" for primitiveJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
331JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
A string can be created in two ways
Ví dụ như,
The former is a primitive
331, while the latter is aJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
1466 objectJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
1466 object is a wrapper for primitive string, which provides many useful methods for manipulating strings. See "The string Type, Literals, and Operations"JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
A
331 primitive is "auto-box" to aJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
1466 object, when you invoke aJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
1466 object's methods. For example,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
The
389 Object vsJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
089 Primitive TypeJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
JavaScript provides primitive
089 type. It also provide aJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
389 class as a wrapper class for primitiveJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
089. Read "The number Type, Literals and Operations" for primitiveJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
089JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
The
389 object is a wrapper object for primitiveJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
089, which provides many properties and methods. Again, aJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
089 primitive is auto-box to aJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
389 object, when you invoke aJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
389 object's operation. See "The number Type, Literals, and Operations"JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
Đối tượng
10 so với loại booleanJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
11JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
JavaScript provides primitive
1168 type. It also provide aJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
10 class as a wrapper class for primitiveJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
1168. Read "The boolean Type, Literals and Operations" for primitiveJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
1168JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
The
10 object is a wrapper object for primitiveJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
1168, which provides many properties and methodsJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
The
058 ObjectJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
Commonly-used constructors
Commonly-used methods
The
40 ObjectJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
Commonly-used properties
Commonly-used methods
The
72 ObjectJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
For an introduction to functions, read "Function" section
Every function in JavaScript is actually a
72 objectFunction VariableJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
A variable can be assigned a
72 object [called function variable], which takes a special object type calledJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
503. [In JavaScript, an object's type is eitherJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
503 [forJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
72 object] orJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
327 [for any object not aJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
72]. ]JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
Ví dụ,
Chức năng ẩn danhIf a function is called only once, you can use an anonymous function, omitting the function name. Anonymous functions are commonly-used as event handler, e. g. ,
You can define a inline [anonymous] function and assign it to a variable as follows
Function ConstructorBesides using
503 keyword, you can also use theJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
72 constructor [withJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
062 operator] to define aJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
72 object. This is not easily understood and, hence, not recommendedJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
Cú pháp cho hàm tạo
72 làJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
144JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
More on Objects
Prototype-based vs. dựa trên lớp
OO của JavaScript dựa trên nguyên mẫu, thay vì dựa trên lớp như Java/C++/C#
Ngôn ngữ OO dựa trên lớp [chẳng hạn như Java/C++/C#] được thành lập dựa trên các khái niệm về lớp và thể hiện. Một lớp là một bản in màu xanh hoặc khuôn mẫu của những thứ cùng loại. Một thể hiện là một hiện thực cụ thể của một lớp. Ví dụ: "
85" là một lớp; . Trong ngôn ngữ OO dựa trên lớp, trước tiên bạn phải viết định nghĩa lớp, trước khi bạn có thể tạo các thể hiện dựa trên định nghĩa lớp. Các thể hiện được tạo có các thuộc tính và phương thức giống hệt như lớp - không hơn, không kémJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
On the other hand, a prototype-based OO language [such as JavaScript] simply has objects [or instances]. A new object can be constructed based on an existing object as prototype. There is no class definition, and hence, they are also called class-less OO languages
In JavaScript
Defining Your Own Custom Objects via a Constructor
In JavaScript, you can create your own custom objects by defining a constructor. A constructor is simply a function, which can be invoked via the
062 operator to create and initialize new objects. Recall that JavaScript is prototype-based and class-less. A new object is created from a prototype object, and gets its initial properties from this prototype object. The constructor function provides the prototype to create and initialize new instances [to be explained later]JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
Theo quy ước, tên hàm tạo bắt đầu bằng một chữ cái viết hoa
Keyword
524JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
"
524" refers to the current object.JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
008 refers to the property of this objectExampleJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
Let us define a constructor for our custom
009 objects, with propertiesJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
010,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
011,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
012 andJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
013Làm thế nào nó hoạt động?JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
Revisit the
89 andJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
032JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
062 OperatorJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
In JavaScript, the
034 call does the followingsJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
Take note that you can invoke the constructor function WITHOUT the
062 operator, e. g. ,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
044. In this case, the constructor will be run as per ordinary function. There will not be any association ofJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
524 andJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
89 properties; and the return value will depend on the function codesJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
Try tracing the object created in the above example via Chrome's Developer Tools, which could display the
89 internal propertyAnother ExampleConstructor'sJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
032 PropertyJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
All the JavaScript constructor function objects [in fact, all function objects] have a special property called
032. By default, it holds an object that can be used as a prototype for creating new objectsJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
In the
009 example, theJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
009 constructor function has aJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
040, which holds aJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
009 object to be used as a prototyping object. When a newJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
009 object is constructed via theJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
062 operator, the newly constructed object'sJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
89 property is set toJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
040Adding Shared properties to Constructor'sJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
032 PropertyJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
The constructor's
032 is used to implement shared properties [typically shared methods] for all the objects it prototyped. In JavaScript, you can add properties dynamically during runtime intoJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
032. The added properties/methods will be available to all the objects [new as well as existing objects]. For example,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
When you reference a property, JavaScript first checks if the property exists locally [or own property]; otherwise, it checks the prototype chain through the
89 property. Recall that theJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
062 call sets theJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
89 toJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
039. Hence, properties added intoJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
039 are available to [and shared by] all the objects prototyped by this constructorJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
In practice, we defines methods [and static variables] in
039 to be shared by all objects; while each object maintains its own properties [instance variables]Looking up the Prototype ChainJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
Objects in JavaScipt form prototype chains. In the above example, a prototype chain is
067JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
When you reference an object property, JavaScript follow these steps to locate the property
Hence, in the above example, all the properties in
040 andJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
92 are inherited byJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
071JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
2909 OperatorJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
Every object has a
89 object property [exceptJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
2901]; every constructor function has aJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
032 property. So objects can be related by 'prototype inheritance' to other objects. You can test for inheritance by comparing an object'sJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
89 to the constructor'sJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
032. JavaScript provides a shortcut. theJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
2909 operator tests an object against a function and returnsJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
041 if the object inherits from the function prototype. For example,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
[LÀM]
080JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
080 lets you create a new object based on the given prototype object. It simply sets theJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
89 to the given prototype object, so that all properties of the prototype are available to the new object. UsingJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
080, You do NOT need to define a constructor function and runJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
084 to create new objectsJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
Inheritance via Prototype Chain
You can implement inheritance in JavaScript via the prototype chain. For example,
How It Works[LÀM]
Getter and Setter
In languages like Java, you can declare a variable to be
085 and defineJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
086 getter/setter to access theJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
085 variable. JavaScript does not really supportJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
085 access?. But you can also define ordinary methodsJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
089 orJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
090 as getter/setter like JavaJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
Moreover, in JavaScript, you can define getter/setter as properties instead of methods in one of the following two ways
091 orJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
092JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
Notes
Notes
2901's PropertiesJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
0002JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
All JavaScript objects inherited a special property called
0003, which contains a reference to the function that created the object. For example,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
[TODO] more Object's properties
API mô hình đối tượng tài liệu [DOM] cho JavaScript
Document Object Model [DOM], is a standard API that allows programmers to access and manipulate the contents of an HTML/XHTML/XML document dynamically inside their program. It models an HTML/XHTML/XML document as an object-oriented, tree-like structure, known as a DOM-tree, consisting of nodes resembling the tags [elements] and contents. DOM also provides an interface for event handling, allowing you to respond to user's or browser's action
DOM API is implemented in many languages such as Java, JavaScript, Perl, and ActiveX. DOM API specification is maintained by W3C. DOM has various levels
jQuery is much better in selecting and manipulating DOM element. You should use jQuery in production. I keep these sections here for completeness
Finding and Selecting Elements
In JavaScript, we often use DOM API to select elements within the current document, so as to access or manipulate their contents. Các chức năng được sử dụng phổ biến nhất là
FunctionDescriptionExample
0004Returns the element with the given uniqueJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
534.JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
146JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
0006Returns an array of elements with the given tag name.JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
147JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
0007Returns an array of elements with the givenJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
0008 attribute name.JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
148JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
0009Returns an array of elements with the givenJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
2918 attribute.JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
149JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
You can use wildcard
0011 inJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
0012 to select all the elements, e. g. ,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
290JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
The above functions select element[s] based on the unique
534,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
2918 attribue and tag-name. HTML 5 further defines two function that can select elements based onJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
0008 attribute [which is used extensively by CSS in the class-selector]FunctionDescriptionExampleJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
0016Returns the first element with the givenJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
0008 attribute.JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
291JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
0018Returns an array of elements with the givenJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
0008 attribute.JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
291JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
Beside the above selection functions, there are many other selection functions available. However, I strongly recommend that you stick to the above functions. I listed below the other function below for completeness
Manipulating Element's Content through the
537 PropertyJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
You can access and modify the content of an element via the "
537" property, which contains all the texts [includes nested tags] within this elementJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
Ví dụ,
"
537" is the most convenient way to access and manipulate an element's content. However, it is not a W3C standard, but it is supported by most of the browsersJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
DOM Tree & Nodes
W3C recommends that you access and manipulate HTML elements via the DOM tree and nodes. However, it is really an overkill for writing simple JavaScripts. I present them here again for completeness
When a browser loads an HTML page, it builds DOM models a web page in a hierarchical tree-like structure composing of nodes, resembling its HTML structure
An example of an HTML document with the corresponding DOM-tree is given follow. Take note that the text content of an element is stored in a separate Text node
293JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
Load the web page onto Firefox, and use the firebug to inspect the DOM tree.
A DOM-tree comprises the following types of nodes
A DOM node has these properties
Take note of the difference between singular and plural terms. For example,
0041 refer to the parent node [each node except root has one and only one parent node],JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
0042 holds an array of all the children nodesJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
The root node of the DOM tree is called
019. The root nodeJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
019 has only one child, calledJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
0051, representing the tag, and it acts as the parent for two child nodes representing and tags, which in turn will have other child nodes. You can also use a special property calledJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
0052 to access the tag directlyJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
For example, you can use the following node property to access the Text node
0053 in the above exampleExampleJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
The following JavaScript lists all the nodes in the section, in a depth-first search manner, via a recursive function
294JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
295JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
Accessing the HTML element via Node interface may not be too useful nor practical for JavaScript applications, as you need to know the actual topological structure of the DOM-tree. Furthermore, some browsers [e. g. , firefox] may create extra Text nodes to contain the white spaces between tags
Text Node
DOM models the texts enclosed by HTML tags as a separate text node. It cannot have child node. To retrieve the text content, you could the property
0037. For example,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
Attribute Properties
To access an attribute of an Element node called
0055, you could either useJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
Ví dụ,
Attribute
0060 [for CSS]JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
Element has a property called style, which models CSS style with CSS properties such as
522 andJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
0062. For example,JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
296JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
Manipulating Nodes
A Node object has these functions
0071] and Text Node [JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
0072], Appending a Node [JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
0073]JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
To create new text node, you can use
0074 to create a standalone text-node, followed by anJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
0075JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
0076 to append the text node to an elementJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
Similarly, you can use
0077 to create a stand-alone element, followed by anJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
0078 to append the created element into an existing elementJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
For example, we shall create a new text node, as a child of a new
element. We shall then append the new
element as the last child of
297Inserting a new Node [JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
0079]JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
297Thay thế một nút [JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
0080]JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
Change the last line to
0081Deleting a Node [JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
0082]JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
You can remove a child node from a parent node via
0083JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
For example, let remove the last
from
299JavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
The
019 objectJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
The
019 object is the root node of the DOM-tree. It can be used to access all the elements in an HTML pageJavaScript Example: Events onload, onmouseover and onmouseout
"Hello" alert Box appears after the page is loaded.
Point your mouse pointer here!!!
What does the below statement evaluate to in JavaScript 4 3 2 1?
But instead, the expression evaluates to "91" , like it's doing 4 + 3 = 7 , 7 + 2 = 9 , 9 + "1" = "91" .Which of the following is the correct way for calling the JavaScript code 1 point a preprocessor B triggering event C RMI D function method?
Correct Option. B JavaScript code can be called by making a function call to the element on which JavaScript has to be run . There are many other methods like title, onload and onsubmit etc.What is the correct JavaScript syntax to change the content of the following HTML code?
The easiest way to modify the content of an HTML element is by using the innerHTML property .Which type of JavaScript language is?
Đó là ngôn ngữ lập trình hướng đối tượng, dựa trên văn bản được sử dụng để làm cho các trang web và ứng dụng trở nên năng động và tương tác hơn cho khách truy cập.