I was looking for javascript documentation and found this I don’t understand how logkey function is working in addeventlistener . when I press a key, the console prints its code but logkey is not having any parameters in addeventlistener. How did it print e.code ? Answer You pass the function as a parameter to the eventListener. The eventListener calls the
Tag: optional-parameters
Using destructuring to define optional parameters in ES6
I have a function that performs an AJAX call, as such: Where the second parameter is optional, i.e. in some cases that parameter is required, in others it isn’t: and: In the second instance I’d like to be able to omit the undefined parameter and I believe assigning options/defaults by way of destructuring is the answer (as per this example:
Is there a way to provide named parameters in a function call in JavaScript?
I find the named parameters feature in C# quite useful in some cases. What can I use if I want this in JavaScript? What I don’t want is this: That approach I’ve already used. Is there another way? I’m okay using any library to do this. Answer ES2015 and later In ES2015, parameter destructuring can be used to simulate named