Message from JavaScript discussions

February 2019

— The function ()?


Ok, let me guess if I understood.

Click button 1, something happen.
Click button 3, nothing happen.


Click button 3, default happen?

— Noo you got confused

— Sorry if i confused you

— 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

Message permanent page

— 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

addEventListener(‘click’, x)

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

Message permanent page