Comparision with null

I use openHAB V5.0.2

Stupid question: what are the right way to compare an variable or Item with null? If I use

if(lastEvccRestart !== null) {
    …
}

then I get in the openhab.log at runtime:

2025-10-20 18:00:00.399 [ERROR] [.handler.AbstractScriptModuleHandler] - Script execution of rule with UID ‘evcc-recovery-6’ failed: Unknown variable or command ‘!==’; line 322, column 8, length 24 in evcc-recovery

But if I use

if(lastEvccRestart != null) {
    …
}

then I get in openhab.log while the rule/rule file is loading:

The operator '!=' should be replaced by '!==' when null is one of the arguments.

So my question is simple: what is the right wayto compare a variable with null?

a === b checks whether both variables are identical (i.e. both pointers direct to the same memory), while
a == b checks whether both variables have the same value.
If comparing with null, it’s not about the actual value but about the state (or maybe better statelessness).

When comparing with null, === (or the negation !==) is the correct way.

It thinks the !== is the name of variable which implies there is a syntax error somewhere further up on the file. It could be the line immediately above or it could be at the top of the file, but somewhere you probably have an opening (e.g. {, (, ', ") without a closing (e.g. }, ), ', "). Or there is something weird a bout the declaration of lastEvccRetstart.

Thanks for your responses! :slight_smile:

Yes, the error occurred earlier. I had used a DateTime type for lastEvccRestart. That type is no longer exists. I had not seen the info message while loading this rule (“… lastEvccRestart refers to the missing type Object …”).