Assigning a function handler to a variable leads me to believe that my variable is now a reference to my function. While this all seems fine and dandy, why can I concatenate a string with my "reference" and why is this concatenation reflected when I write my "reference" to the screen?
Why is my function reference being both handled and written as a string?
What is going on behind the scenes with references and type?
var x = tester;
document.getElementById("test_button").onclick = x;
document.getElementById("test_p").innerHTML += (x + "<br>");
x += "Did I just concatenate a string?";
document.getElementById("test_p").innerHTML += (x);
function tester() {
document.write("Hello World!");
}
<button id="test_button">Press Me</button>
<br>
<p id="test_p"></p>
I assign the reference as an onclick for a button, and the function still executes as expected.
[Press Me]
function tester() { document.write("Hello World!"); }
function tester() { document.write("Hello World!"); }Did I just concatenate
a string?
Above is output, and when the button is pressed "Hello World!" is written to the screen.