JavaScript là một trong những ngôn ngữ lập trình được giải thích, nhẹ và được biên dịch phổ biến nhất. Nó là đồng bộ và đơn luồng. Các chương trình trong JavaScript được gọi là tập lệnh được thực thi dưới dạng văn bản thuần túy. Chúng tôi có thể viết các tập lệnh này trực tiếp trên trang HTML của mình hoặc sử dụng tệp JavaScript bên ngoài. JavaScript có thể thực thi trong trình duyệt và cả trên máy chủ hoặc trên thực tế trên bất kỳ thiết bị nào có chương trình đặc biệt gọi là công cụ JavaScript. JavaScript được sử dụng cho phía máy chủ cũng như trong các phát triển phía máy khách
Có 2 cách để sử dụng javascript trong tệp HTML
- Internal JavaScript: JavaScript can be added directly to the HTML file by writing the code inside the tag . We can place the tag either inside or the tag according to the need.
- External JavaScript: The other way is to write JavaScript code in another file having a .js extension and then link the file inside the or tag of the HTML file in which we want to add this code.
Ví dụ. Ví dụ này mô tả việc sử dụng Javascript nội bộ
HTML
Hi Geeks, Welcome to GfG2
Hi Geeks, Welcome to GfG8_______0_______0
>
Hi Geeks, Welcome to GfG2
Hi Geeks, Welcome to GfG2
/script>3>
>/script>
5Hi Geeks, Welcome to GfG
2
>/script>
7Hi Geeks, Welcome to GfG
2
>/script>
9Hi Geeks, Welcome to GfG
2Hi Geeks, Welcome to GfG
8
>/script>
3>
Hi Geeks, Welcome to GfG
8
3>
Hi Geeks, Welcome to GfG
8_______109_______>
đầu ra
Hi Geeks, Welcome to GfG
Ví dụ. Ví dụ này mô tả việc sử dụng Javascript bên ngoài
HTML
Hi Geeks, Welcome to GfG
2
Hi Geeks, Welcome to GfG
8_______0_______0>
Hi Geeks, Welcome to GfG
2
7
>/script>
5Hi Geeks, Welcome to GfG
2/script>3
2
3
4
5
>/script>
3
7Hi Geeks, Welcome to GfG
8
3>
Hi Geeks, Welcome to GfG
8_______109_______>
tệp bên ngoài. GfG. js
Javascript
Ví dụ. Ví dụ này mô tả việc sử dụng các tệp javascript bên ngoài trong đó một con trỏ di chuyển văn bản cụ thể sau đó văn bản thay đổi thành một văn bản khác
HTML
Hi Geeks, Welcome to GfG
2
Hi Geeks, Welcome to GfG
2
Hi Geeks, Welcome to GfG
2Hi Geeks, Welcome to GfG
17Hi Geeks, Welcome to GfG
18Hi Geeks, Welcome to GfG
19Hi Geeks, Welcome to GfG
18Hi Geeks, Welcome to GfG
21Hi Geeks, Welcome to GfG
18Hi Geeks, Welcome to GfG
23Hi Geeks, Welcome to GfG
18Hi Geeks, Welcome to GfG
25
Hi Geeks, Welcome to GfG
18Hi Geeks, Welcome to GfG
27Hi Geeks, Welcome to GfG
18Hi Geeks, Welcome to GfG
29Hi Geeks, Welcome to GfG
18Hi Geeks, Welcome to GfG
31Hi Geeks, Welcome to GfG
18Hi Geeks, Welcome to GfG
33Hi Geeks, Welcome to GfG
18Hi Geeks, Welcome to GfG
35Hi Geeks, Welcome to GfG
18Hi Geeks, Welcome to GfG
37Hi Geeks, Welcome to GfG
2Hi Geeks, Welcome to GfG
39Hi Geeks, Welcome to GfG
2Hi Geeks, Welcome to GfG
8Hi Geeks, Welcome to GfG
14>
Hi Geeks, Welcome to GfG
8_______0_______0>
Hi Geeks, Welcome to GfG
2
Hi Geeks, Welcome to GfG
2/script>3
2
3
4
5
>/script>
3>
Hi Geeks, Welcome to GfG
8
3>
Hi Geeks, Welcome to GfG
8_______109_______>
mã JS
GfG. js
Hi Geeks, Welcome to GfG
76Hi Geeks, Welcome to GfG
77