Sample 1:
var someText = "Ein Hund kam in die Küche und stahl dem Koch ein Ei."; // Some Strings
var moreText = "Da nahm der Koch den Löffel und schlug den Hund entzwei.";
var someNumber = 34; // Some Numbers
var anotherNumber = 98;
function testFunc(){
var box_uno = document.getElementById("output1"); // "output1" references a <textarea>
box_uno.innerHTML = someText;
}
Sample 2:
var someText = "Ein Hund kam in die Küche und stahl dem Koch ein Ei."; // Some Strings
var moreText = "Da nahm der Koch den Löffel und schlug den Hund entzwei.";
var someNumber = 34; // Some Numbers
var anotherNumber = 98;
var box_uno = document.getElementById("output1"); // "output1" references a <textarea>
function testFunc(){
box_uno.innerHTML = someText;
}
Sample 1 works fine. The string is displayed in the textarea as expected.
Sample 2 doesn't work and I'd like to fully understand why. I thought variables which are declared outside of a function have global scope. I don't get why I can access the variables with strings and numbers from inside the function, but not the variable containing a html-element.