0

So, I saw this video https://youtu.be/YylKa3C_qQc and it mentioned:

const hotkeys = (e) => { let windowEvent ? Window.event : e; }

As a new JavaScript programmer, I don't know how this is working. How does this work? windowEvent ? Window.event : e;. All I know is that this is a ternary operator.

Mr. Polywhirl
  • 31,606
  • 11
  • 65
  • 114
Sagar
  • 1
  • 1
  • A [ternary operator (MDN)](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Conditional_Operator) is an in-line `if-else` shorthand. – Mr. Polywhirl May 21 '21 at 15:35
  • 1
    `window.event` is a [quite old and nowadays deprecated](https://developer.mozilla.org/en-US/docs/Web/API/Window/event) way of accessing a DOM event. I think the code you provided is either trying to be backward-compatible or very defensive. I personally haven’t seen it for a while, usually working with event handler arguments (in your example, it’s `e`) is enough. – rishat May 21 '21 at 15:36
  • Thanks. This small knowledge is going to go a long way – Sagar May 21 '21 at 18:22

0 Answers0