Message from JavaScript discussions

February 2019

— Button 1 is for something different

— 

Well, for start your variable x is always defined, you have to modify this variable INSIDE de function to be useful

— Yeah i have already defined it to be 1

— I mean when you do this

addEventListener(‘click’, x=function(){})

This will evaluate your expression assignment x=function(){} and will return the function

So the line above is almost the same as

x=function(){}
addEventListener(‘click’, x)

That’s why it will always your conditional if (x) be true

Message permanent page

— He's calling logic function with passed parameter when button is clicked

— The problem here is the conditional is called as son as the event trigger is set. It’s almost instantaneous.

Message permanent page

— Yeah it will be called

— And if it is called

— 0 is returned

— X is storing 0

— Which makes if(x) false

— If button clicked