Simple question on boolean function return value

16 views
Skip to first unread message

Janis Papanagnou

unread,
Jan 13, 2023, 9:56:58 AMJan 13
to
Today I was surprised that some old code did not work as I'd have
expected:

function friday_13th (now)
{
return now.getDay()==5 && now.getDate==13;
}

That function returned 'false' and also putting parenthesis around
the (sub-) expressions did not help. I had to use a local variable
to make that work:

function friday_13th (now)
{
var f13 = now.getDay()==5 && now.getDate()==13;
return f13;
}

Can anyone explain that please?

Janis

Janis Papanagnou

unread,
Jan 13, 2023, 10:23:23 AMJan 13
to
On 13.01.2023 16:09, Stefan Ram wrote:
> Janis Papanagnou <janis_pa...@hotmail.com> writes:
>> return now.getDay()==5 && now.getDate==13;
>
> There is a pair of parentheses missing above.

Argh! - I had been looking so long at that code that I obviously
got "code-blind". - Thanks!

Janis

V V V V V V V V V V V V V V V V V V

unread,
Jan 28, 2023, 12:06:03 PMJan 28
to
P i c t u r e , ⠀⠀⠀p a r d o n ?
Reply all
Reply to author
Forward
0 new messages