What is the difference between a function call and function reference?

前端 未结 6 2466
别跟我提以往
别跟我提以往 2020-11-22 05:50

I have the following function

function hello() {
 alert(\"hi!\");
}

Take this piece of code:

var elem = document.getElem         


        
6条回答
  •  庸人自扰
    2020-11-22 06:15

    hello() means you call that function, which means the function will be executed directly.

    while when you have elem.onclick = hello, this is called a callback. Where hello doesn't get executed directly but only when a certain event is fired (in this case when there's a click on the element)

提交回复
热议问题