0

For example, this code snippet:

var key = e.charCode ? e.charCode : e.keyCode ? e.keyCode : 0;

What does the ? do?

Update for anyone searching: This link provides a good explanation with examples

JavaScript ternary operator example with functions

Community
  • 1
  • 1
  • 5
    That's a ternary operator, not related to jQuery: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Conditional_Operator – A. Wolff Jun 11 '15 at 20:02
  • Exactly the same thing it does in JavaScript or any other C-descendant language. – PM 77-1 Jun 11 '15 at 20:03
  • 1
    FYI, because jQuery event is normalized, you could simplify it to: `var key = e.which || 0;` – A. Wolff Jun 11 '15 at 20:07
  • This is a more useful and explanatory link with examples than the duplicate one http://stackoverflow.com/questions/10323829/javascript-ternary-operator-example-with-functions –  Jun 11 '15 at 20:11

0 Answers0