how a code var charCode = (evt.which) ? evt.which : event.keyCode could be explaned?
what happens here ?
all i understand is that clause returns buttons value to the object charCode.
but what those ? and : signs mean?
and can i use this thing in other languager? java/c++/php and so on?
Thanks
how a code var charCode = (evt.which) ? evt.which : event.keyCode could be explaned?
Share
It’s called the ternary conditional operator. It’s basically short for an
if...else:Basically, it evaluates the first operand. If that evaluation returns
true, the second operand is returned. Iffalse, the third is returned.As for whether you can use it in other languages, you often can. From the languages you listed, Java and PHP both have it, and I’d be very surprised if C++ didn’t (edit – a quick Google reveals that C and C++ do indeed support it too). For more, see Wikipedia.