Message from JavaScript discussions

February 2019

— There are two buttons 2 and 3

— 

Button 2, function call for some value
Button 3, same function call for a different value

If no button clicked out of the two, call same function for default value

— Nice

— You mean when button 1 is clicked to call the default value?

— 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

Message permanent page

— 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