JavaScript adalah salah satu bahasa pemrograman yang ditafsirkan, ringan, dan dikompilasi yang paling populer. Ini sinkron dan single-threaded. Program dalam JavaScript disebut skrip yang dijalankan sebagai teks biasa. Kami dapat menulis skrip ini langsung di halaman HTML kami atau menggunakan file JavaScript eksternal. JavaScript dapat dijalankan di browser, dan juga di server, atau sebenarnya di perangkat apa pun yang memiliki program khusus yang disebut mesin JavaScript. JavaScript digunakan untuk sisi server dan juga dalam pengembangan sisi klien
Ada 2 cara untuk menggunakan javascript dalam file 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.
Contoh. Contoh ini menjelaskan penggunaan Javascript Internal
HTML
Hi Geeks, Welcome to GfG2
Hi Geeks, Welcome to GfG8
Hi Geeks, Welcome to GfG0
>
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
8html
>
Keluaran
Hi Geeks, Welcome to GfG
Contoh. Contoh ini menjelaskan penggunaan Javascript Eksternal
HTML
Hi Geeks, Welcome to GfG
2
Hi Geeks, Welcome to GfG
8Hi Geeks, Welcome to GfG
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
8html
>
Berkas eksternal. GfG. js
Javascript
Hi Geeks, Welcome to GfG
8Hi Geeks, Welcome to GfG
0>
Hi Geeks, Welcome to GfG
2________108_7_______7 Hi Geeks, Welcome to GfG
54
3Hi Geeks, Welcome to GfG
56
8
7>
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
8html
>
Kode JS
GfG. js
Hi Geeks, Welcome to GfG
76Hi Geeks, Welcome to GfG
77