I'm trying to familiarize myself with Javascript, and this is a behavior I've seen trying to work on my calculator.
setup();
function setup(){
element = document.getElementById("1");
console.log(element);
if(element.innerHTML === "1"){
var test = element;
element.onclick = test1;
element.onclick = test2;
}
}
function test2(){
console.log("Test2 function");
}
function test1(){
console.log("Test1 Function");
}
How come if I run this, only the test2 function returns a log, does it only return the last function called, or is it a behavior of the .onclick function?
Now if I try calling the test1 function from inside test2 like this, it still doesn't work.
function test2(){
console.log("Test2 function");
test1;
}
But if I instead do this:
function test2(){
console.log("Test2 function");
test1();
}
It logs both of them. How come? I'm used to Ruby if that is relevant.
==================================
Also another question, what is the difference between
function test(){
return function(){
console.log("test!");
}
}
to
function test(){
console.log("test");
}
innerHTMLalways returns a string, so there's no need to do a strict assessment on its value.