Why do functions nested in an anonymous function wait for button click (as it should), but when the function is not nested it runs on page load without waiting for button click?
Working example:
btn1.onclick = function() {cityChoice(1)};
//code works only on button click as expected
Not working example:
btn1.onclick = cityChoice(1);
//function runs on pageload without waiting for button click?
Any links to documentation/articles are welcome, as I could not find them on Google nor on StackOverflow that explained this.
Coding language: JavaScript (vanilla)
Skill level: Beginner
Editor: Visual Studio Code
OS: Windows 7