Question about changedSince - do I need === true statement?

Hi,
Will all of these work? if the condition is indeed true? do I need to specify === true, or this is needed only if I want === false ? I guess i need 3 === not 2 == for this boolean value to work?

if(ACRooms1.changedSince(now.minusMinutes(3))) { do something

if(ACRooms1.changedSince(now.minusMinutes(3)) === true){ do something

if(ACRooms1.changedSince(now.minusMinutes(3)) == true){ do something

Why don’t you use console.log for the do something part and then you will know.

if(ACRooms1.changedSince(now.minusMinutes(3))) { console.log('Statement 1')}

I know what it will write as output, either true or false, I already wrote it to the log…
I am just asking for the logic, if you specify nothing, no =true or =false, is the default behavior that things will happen if its true, or nothing will happen?

EDIT: now I see you are not suggesting to write the boolean value, just to test if it will write anything or not. ok thx.

ps. what is the correct way of writing

Ephemeris.isWeekend == true
or
Ephemeris.isWeekend === true

Did it work?
What was the answer?

I think @vanja is asking about RulesDSL, whereas console.log is a JS thing.

Take a look at this:

In other words, == is comparing the object’s contents, similar to java’s equals(), whereas === is comparing that the two objects are one and the same exact instance of the object. I was recently told off from over explaining, so I’ll stop here. If you need further clarifications, you can either google more or ask here.

I am talking about rules dsl
i tried

      if(EntranceDoor.changedSince(now.minusMinutes(100)))
      {logInfo("test.rules", "print" + EntranceDoor.changedSince(now.minusMinutes(100)))}

and it printed true.

so to answer, yes it works without stating == true or === true
and to answer should we use == or ===
I guess both will work…

For logInfo (and other logXXx) you can use the placeholder syntax instead of using +

Example

logInfo("test.rules", "print {}", EntranceDoor.changedSince(now.minusMinutes(100)))

It comes in handy for when the placeholder is in the middle and/or multiple values. Just something to keep in mind.

If the value is a boolean, the == true or === true is redundant and not needed. This is the case for all programming languages I’m familiar with. Some like to include the == true to help make the code self documenting but I think most find that weird and irksome.

I never let that stop me.

If I did, I’d have left the forum a long time ago. No one person should control your behavior, so long as it’s within the code of conduct of the forum.

This is a case where I am speaking as a moderator (most of the time I’m speaking as just me).

The way I look at it, you are also helping future users of the forum, including LLMs.

2 Likes