# Pengenalan Javascript

Javascript merupakan bahasa pemrograman yang awalnya hanya bisa berjalan di browser. Namun belakangan, javascript juga bisa jalan di server, sehingga popularitas javascript meningkat dengan drastis. Javascript bisa digunakan untuk membangun frontend web, API backend, frontend mobile, desktop, dan iot.

Untuk tahap awal, kita akan belajar javascript yang berjalan di browser. Ada tiga cara untuk menulis kode javascript di HTML, yaitu : Inline, Embed dan external.&#x20;

## Inline&#x20;

Kode javascript ditempel langsung pada properti HTML.

```markup
<button onclick="alert('Hi')">Say Hi</button>
```

## Embed

Kode javascript ditulis langsung sebagai tag element \<script>\</script> di HTML.

```markup
<!DOCTYPE html>
<html>
  <head>
    <title>Javascript</title>
  </head>
  <body>
    Internal Javascript
    <script>
      console.log("embed javascript");
    </script>
  </body>
</html>
```

Kode di atas akan menampilkan tulisan "Internal Javascript" di browser. Sementara kode javascript akan menampilkan log "embed javascript" di console browser. Untuk melihat console browser, tampilkan developer tools dan klik tab console.

![](/files/-MiEvJE8UOtl6ZJ0HfeL)

## External

Kode javascript ditulis di file terpisah dan dipanggil melalui link.&#x20;

{% tabs %}
{% tab title="HTML" %}
{% code title="index.html" %}

```markup
<!DOCTYPE html>
<html>
  <head>
    <title>Javascript</title>
    <script src="index.js"></script>
  </head>
  <body>
    External Javascript
  </body>
</html>
```

{% endcode %}
{% endtab %}

{% tab title="Javascript" %}
{% code title="index.js" %}

```javascript
console.log("external javascript")
```

{% endcode %}
{% endtab %}
{% endtabs %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://seri-belajar-pemrograman.rijalasepnugroho.com/javascript/pengenalan-javascript.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
