my question is why myFunction2 is triggered immediately, how javascript works like this? thanks.
<!--when passing "myFunction1" without (), myFunction1 is triggered after 3 seconds as expected-->
<button onclick="setTimeout(myFunction1, 3000);">Try it 1</button>
<script>
function myFunction1() {
alert('Hello');
}
</script>
<!--when passing "myFunction2" with (), myFunction1 is triggered right away as clicking the button-->
<button onclick="setTimeout(myFunction2(), 3000);">Try it 2</button>
<script>
function myFunction2() {
alert('Hello');
}
</script>