Reputation: 13699
I was going through some of StackOverflow's client side code and I ran across this block of JavaScript in the source-code of https://stackoverflow.com/questions/ask
:
if ($answerCheckbox.is(':checked') || 0 > 0) {
$answerCheckbox.attr('checked', true);
$('#question-only-section').hide();
StackExchange.using("editor", function () {
setTimeout(function () { showAnswerSection(true) }, 2);
});
}
Why wouldn't you use false
instead?
Upvotes: 15
Views: 451
Reputation: 12059
There is no reason for it... but until you know the server side code, you can't know for sure.
Let's say (PHP) you had a variable $x=1
and could also be $x=0
depending on the scenario.
if ($answerCheckbox.is(':checked') || <?php echo $x;?> > 0) {
That code makes perfect sense....
Upvotes: 6
Reputation: 50573
Because that line probably comes from php, like so:
if ($answerCheckbox.is(':checked') || <?php echo $tot; ?> > 0) {
I know because in some situations I had to write code like that.
Upvotes: 4
Reputation: 318518
It is generated code (not in a .js) file so obviously one of those two values is not always 0 but a server-side variable.
Upvotes: 6
Reputation: 10184
You're assuming the code is all natively written Javascript. It isn't uncommon to see some server-generated script which references elements via some programmatic identifier which resolves like this at runtime, which admittedly looks a little peculiar.
Upvotes: 15