Defined test
Learn how to check if a value is defined.
This test checks whether the value of an operand is defined.
An operand is considered defined when it can be resolved to a value, meaning it is not null or undefined. If an operand throws an error, it is considered undefined. For example, if you try to access a property that does not exist, such as a query parameter that does not exist in the current URL, the result is false, not an error.
This test does not check if the value is empty, only if it is defined. For empty checks, use the empty test instead.
Syntax
This test has the following syntax:
/*<value>*/ is defined
You can alternatively use the following syntax:
/*<value>*/ is known
Both forms have the same semantics. You can use whichever makes your query more expressive and easier to read.
To negate the test, use the following syntax:
/*<value>*/ is not defined
Parameters
These are the supported parameters:
- valueany
The value to validate.
Examples
Here is a practical example of the defined test:
page's query's code is defined
The above expression returns true if the current page URL contains a query parameter named code, regardless of its value.
You can also use the alternative syntax to achieve the same result:
page's query's code is known