|
1 |
| -# Hello, world! |
| 1 | +# Hallo, wereld! |
2 | 2 |
|
3 |
| -This part of the tutorial is about core JavaScript, the language itself. |
| 3 | +Dit deel van de tutorial gaat over de kern van JavaScript, de taal zelf. |
4 | 4 |
|
5 |
| -But we need a working environment to run our scripts and, since this book is online, the browser is a good choice. We'll keep the amount of browser-specific commands (like `alert`) to a minimum so that you don't spend time on them if you plan to concentrate on another environment (like Node.js). We'll focus on JavaScript in the browser in the [next part](/ui) of the tutorial. |
| 5 | +Maar we hebben een werkomgeving nodig om onze scripts uit te voeren en aangezien dit boek online is, is de browser een goede keuze. We zullen de hoeveelheid browser-specifieke commando's (zoals `alert`) tot een minimum beperken zodat je er geen tijd aan besteedt als je van plan bent je te concentreren op een andere omgeving (zoals Node.js). We zullen ons concentreren op JavaScript in de browser in het [next part](/ui) van de tutorial. |
6 | 6 |
|
7 |
| -So first, let's see how we attach a script to a webpage. For server-side environments (like Node.js), you can execute the script with a command like `"node my.js"`. |
| 7 | +Dus laten we eerst eens kijken hoe we een script aan een webpagina koppelen. Voor server-side omgevingen (zoals Node.js) kun je het script uitvoeren met een commando als `"node my.js"`. |
8 | 8 |
|
9 | 9 |
|
10 |
| -## The "script" tag |
| 10 | +## De "script" tag |
11 | 11 |
|
12 |
| -JavaScript programs can be inserted into any part of an HTML document with the help of the `<script>` tag. |
| 12 | +JavaScript-programma's kunnen in elk deel van een HTML-document worden ingevoegd met behulp van de `<script>`-tag. |
13 | 13 |
|
14 |
| -For instance: |
| 14 | +Bijvoorbeeld: |
15 | 15 |
|
16 | 16 | ```html run height=100
|
17 | 17 | <!DOCTYPE HTML>
|
18 | 18 | <html>
|
19 | 19 |
|
20 | 20 | <body>
|
21 | 21 |
|
22 |
| - <p>Before the script...</p> |
| 22 | + <p>Voor het script...</p> |
23 | 23 |
|
24 | 24 | *!*
|
25 | 25 | <script>
|
26 |
| - alert( 'Hello, world!' ); |
| 26 | + alert( 'Hallo, wereld!' ); |
27 | 27 | </script>
|
28 | 28 | */!*
|
29 | 29 |
|
30 |
| - <p>...After the script.</p> |
| 30 | + <p>...Na het script.</p> |
31 | 31 |
|
32 | 32 | </body>
|
33 | 33 |
|
34 | 34 | </html>
|
35 | 35 | ```
|
36 | 36 |
|
37 | 37 | ```online
|
38 |
| -You can run the example by clicking the "Play" button in the right-top corner of the box above. |
| 38 | +U kunt het voorbeeld uitvoeren door te klikken op de knop "Afspelen" in de rechterbovenhoek van het vak hierboven. |
39 | 39 | ```
|
40 | 40 |
|
41 |
| -The `<script>` tag contains JavaScript code which is automatically executed when the browser processes the tag. |
| 41 | +Het `<script>`-tag bevat JavaScript-code die automatisch wordt uitgevoerd wanneer de browser de tag verwerkt. |
42 | 42 |
|
43 | 43 |
|
44 |
| -## Modern markup |
| 44 | +## Moderne opmaak |
45 | 45 |
|
46 |
| -The `<script>` tag has a few attributes that are rarely used nowadays but can still be found in old code: |
| 46 | +Het `<script>` tag heeft een aantal attributen die tegenwoordig zelden gebruikt worden, maar nog wel in oude code te vinden zijn: |
47 | 47 |
|
48 |
| -The `type` attribute: <code><script <u>type</u>=...></code> |
49 |
| -: The old HTML standard, HTML4, required a script to have a `type`. Usually it was `type="text/javascript"`. It's not required anymore. Also, the modern HTML standard totally changed the meaning of this attribute. Now, it can be used for JavaScript modules. But that's an advanced topic, we'll talk about modules in another part of the tutorial. |
| 48 | +Het `type`-attribuut: <code><script <u>type</u>=...></code> |
| 49 | +: De oude HTML-standaard, HTML4, vereiste een script om een `type` te hebben. Meestal was het `type="tekst/javascript"`. Het is niet meer nodig. Ook de moderne HTML-standaard heeft de betekenis van dit attribuut totaal veranderd. Nu kan het gebruikt worden voor JavaScript-modules. Maar dat is een geavanceerd onderwerp, we zullen het in een ander deel van de tutorial over modules hebben. |
50 | 50 |
|
51 |
| -The `language` attribute: <code><script <u>language</u>=...></code> |
52 |
| -: This attribute was meant to show the language of the script. This attribute no longer makes sense because JavaScript is the default language. There is no need to use it. |
| 51 | +Het `taal`-attribuut: <code><script <u>taal</u>=...></code> |
| 52 | +: Dit attribuut was bedoeld om de taal van het script te laten zien. Dit attribuut heeft geen zin meer omdat JavaScript de standaard taal is. Het is niet nodig om het te gebruiken. |
53 | 53 |
|
54 |
| -Comments before and after scripts. |
55 |
| -: In really ancient books and guides, you may find comments inside `<script>` tags, like this: |
| 54 | +Commentaar voor en na scripts. |
| 55 | +: In echt oude boeken en gidsen vind je misschien commentaar in `<script>`-tags, zoals deze: |
56 | 56 |
|
57 | 57 | ```html no-beautify
|
58 |
| - <script type="text/javascript"><!-- |
| 58 | + <script type="tekst/javascript"><! -- |
59 | 59 | ...
|
60 | 60 | //--></script>
|
61 | 61 | ```
|
62 | 62 |
|
63 |
| - This trick isn't used in modern JavaScript. These comments hide JavaScript code from old browsers that didn't know how to process the `<script>` tag. Since browsers released in the last 15 years don't have this issue, this kind of comment can help you identify really old code. |
| 63 | + Deze truc wordt niet gebruikt in moderne JavaScript. Deze commentaren verbergen JavaScript-code voor oude browsers die niet wisten hoe ze de `<script>`-tag moesten verwerken. Aangezien browsers die in de afgelopen 15 jaar zijn uitgebracht dit probleem niet hebben, kan dit soort commentaar u helpen bij het identificeren van echt oude code. |
64 | 64 |
|
65 | 65 |
|
66 |
| -## External scripts |
| 66 | +## Externe scripts |
67 | 67 |
|
68 |
| -If we have a lot of JavaScript code, we can put it into a separate file. |
| 68 | +Als we veel JavaScript-code hebben, kunnen we die in een apart bestand zetten. |
69 | 69 |
|
70 |
| -Script files are attached to HTML with the `src` attribute: |
| 70 | +Scriptbestanden worden aan HTML gekoppeld met het `src` attribuut: |
71 | 71 |
|
72 | 72 | ```html
|
73 |
| -<script src="/path/to/script.js"></script> |
| 73 | +<script src="/pad/naar/script.js"></script> |
74 | 74 | ```
|
75 | 75 |
|
76 |
| -Here, `/path/to/script.js` is an absolute path to the script from the site root. One can also provide a relative path from the current page. For instance, `src="script.js"` would mean a file `"script.js"` in the current folder. |
| 76 | +Hier is `/pad/naar/script.js` een absoluut pad naar het script vanuit de site-root. Men kan ook een relatief pad van de huidige pagina opgeven. Bijvoorbeeld, `src="script.js "betekent een bestand `"script.js"` in de huidige map. |
77 | 77 |
|
78 |
| -We can give a full URL as well. For instance: |
| 78 | +We kunnen ook een volledige URL geven. Bijvoorbeeld: |
79 | 79 |
|
80 | 80 | ```html
|
81 | 81 | <script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.11/lodash.js"></script>
|
82 | 82 | ```
|
83 | 83 |
|
84 |
| -To attach several scripts, use multiple tags: |
| 84 | +Om meerdere scripts te bevestigen, gebruik je meerdere tags: |
85 | 85 |
|
86 | 86 | ```html
|
87 | 87 | <script src="/js/script1.js"></script>
|
88 | 88 | <script src="/js/script2.js"></script>
|
89 | 89 | …
|
90 | 90 | ```
|
91 | 91 |
|
92 |
| -```smart |
93 |
| -As a rule, only the simplest scripts are put into HTML. More complex ones reside in separate files. |
| 92 | +```slimme |
| 93 | +In de regel worden alleen de eenvoudigste scripts in HTML gezet. Complexere scripts staan in aparte bestanden. |
94 | 94 |
|
95 |
| -The benefit of a separate file is that the browser will download it and store it in its [cache](https://en.wikipedia.org/wiki/Web_cache). |
| 95 | +Het voordeel van een apart bestand is dat de browser het downloadt en opslaat in zijn [cache](https://en.wikipedia.org/wiki/Web_cache). |
96 | 96 |
|
97 |
| -Other pages that reference the same script will take it from the cache instead of downloading it, so the file is actually downloaded only once. |
| 97 | +Andere pagina's die naar hetzelfde script verwijzen zullen het uit de cache halen in plaats van het te downloaden, zodat het bestand eigenlijk maar één keer wordt gedownload. |
98 | 98 |
|
99 |
| -That reduces traffic and makes pages faster. |
| 99 | +Dat vermindert het verkeer en maakt de pagina's sneller. |
100 | 100 | ```
|
101 | 101 |
|
102 |
| -````warn header="If `src` is set, the script content is ignored." |
103 |
| -A single `<script>` tag can't have both the `src` attribute and code inside. |
| 102 | +````warn header="Als `src` is ingesteld, wordt de inhoud van het script genegeerd." |
| 103 | +Een enkele `<script>` tag kan niet zowel het `src` attribuut als de code bevatten. |
104 | 104 |
|
105 |
| -This won't work: |
| 105 | +Dit werkt niet: |
106 | 106 |
|
107 | 107 | ```html
|
108 |
| -<script *!*src*/!*="file.js"> |
109 |
| - alert(1); // the content is ignored, because src is set |
| 108 | +<script *! *src*/! *="file.js"> |
| 109 | + waarschuwing(1); // de inhoud wordt genegeerd, omdat src is ingesteld |
110 | 110 | </script>
|
111 | 111 | ```
|
112 | 112 |
|
113 |
| -We must choose either an external `<script src="…">` or a regular `<script>` with code. |
| 113 | +We moeten kiezen voor een externe `<script src="...">" of een gewone `<script>` met code. |
114 | 114 |
|
115 |
| -The example above can be split into two scripts to work: |
| 115 | +Het bovenstaande voorbeeld kan worden opgesplitst in twee scripts om te werken: |
116 | 116 |
|
117 | 117 | ```html
|
118 |
| -<script src="file.js"></script> |
| 118 | +<script src="bestand.js"></script> |
119 | 119 | <script>
|
120 |
| - alert(1); |
| 120 | + waarschuwing(1); |
121 | 121 | </script>
|
122 | 122 | ```
|
123 | 123 | ````
|
124 | 124 |
|
125 |
| -## Summary |
| 125 | +## Samenvatting |
126 | 126 |
|
127 |
| -- We can use a `<script>` tag to add JavaScript code to a page. |
128 |
| -- The `type` and `language` attributes are not required. |
129 |
| -- A script in an external file can be inserted with `<script src="path/to/script.js"></script>`. |
| 127 | +- We kunnen een `<script>` tag gebruiken om JavaScript-code toe te voegen aan een pagina. |
| 128 | +- De `type` en `taal` attributen zijn niet nodig. |
| 129 | +- Een script in een extern bestand kan worden ingevoegd met `<script src="path/to/script.js"></script>`. |
130 | 130 |
|
131 | 131 |
|
132 |
| -There is much more to learn about browser scripts and their interaction with the webpage. But let's keep in mind that this part of the tutorial is devoted to the JavaScript language, so we shouldn't distract ourselves with browser-specific implementations of it. We'll be using the browser as a way to run JavaScript, which is very convenient for online reading, but only one of many. |
| 132 | +Er is nog veel meer te leren over browserscripts en hun interactie met de webpagina. Maar laten we niet vergeten dat dit deel van de tutorial gewijd is aan de JavaScript-taal, dus we moeten onszelf niet afleiden met browser-specifieke implementaties ervan. We zullen de browser gebruiken als een manier om JavaScript uit te voeren, wat erg handig is voor online lezen, maar slechts één van de vele. |
0 commit comments