0
window.onload = function () {
    'use strict';

What does this mean?

var antwoord = function (tekst) {
    var berichtvenster = document.getElementById('berichtvenster');
    berichtvenster.innerHTML += "<p>" + tekst + "</p>\n";

And what is the code above doing? Step by step? I think it makes a function (antwoord) and var berichtvenster takes the (berichtvenster ID) from HTML? berichtvenster.innerHTML prints out tekst on different textline? Am i right?

Michael Berkowski
  • 267,341
  • 46
  • 444
  • 390
  • I'm not going to copy info here, but please referrer to MDN. https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Functions_and_function_scope/Strict_mode – roydukkey Apr 11 '13 at 13:16
  • Contents of the variable `tekst` are added inside a `

    ` to the existing contents of the element whose id is `berichtvenster`.

    – Michael Berkowski Apr 11 '13 at 13:16
  • The 'Use Strict' keyword has also been answered here: http://stackoverflow.com/questions/1335851/what-does-use-strict-do-in-javascript-and-what-is-the-reasoning-behind-it – KernelPanik Apr 11 '13 at 13:19

1 Answers1

2
window.onload = function () {

This line initiates an anonymous function and appends it to the window.onload event, i.e. the code within the function will be executed at when the page and all its resources are loaded in the DOM.

'use strict';

This line says that the proceeding code is to be executed in strict mode, which means that a handful of common pitfalls and dubious codes will be treated as errors. See more on strict mode here.

var antwoord = function(tekst) {

This line initiates a function named antwoord (not really: see comments) that accepts one parameter (tekst).

var berichtvenster = document.getElementById('berichtvenster');

This line looks for an element of the ID "berichtvenster", and assigns a reference to that element, if any is found, to the newly created variable of the same name.

berichtvenster.innerHTML += "<p>" + tekst + "</p>\n";

This line assumes that such an element was indeed found, and proceeds to update its innerHTML property, i.e. to change the HTML content of the element. It changes the content to be a paragraph containing only the text that was passed to the antwoord function.

David Hedlund
  • 128,221
  • 31
  • 203
  • 222