# Query parameters https://www.sanity.io/learn/course/between-groq-and-a-hard-place/conditional-parameters.md Use parameters as variables in your queries, whether they have values or not. ## Static parameters The most common use case for using parameters in GROQ for front ends is matching a document against its slug, using a dynamic value from your front end framework. 1. Query for a single event with this matching slug. If you used the seed data in a previous course this document should exist. ```groq:Query *[ _type == "event" && slug.current == $slug ][0] ``` ```json:Parameters { "slug": "the-national-at-the-bowery-ballroom" } ``` This should return a single document. Using parameters in GROQ queries is superior and safer than string concatenation in JavaScript. In the bad example below the variable needs to be wrapped in quotes and can be easily formatted incorrectly. ```javascript // ❌ Avoid doing this, use params instead! const EVENT_QUERY = `*[ _type == "event" && slug.current == "${slug}" ][0]` ``` ## Conditional parameters You can use `select` to conditionally use a parameter to filter documents. 1. Query to return the `name` of future events if a date is provided, or all events if not. ```groq:Query *[ _type == "event" && select( defined($date) => date > now(), true ) ].name ``` ```json:Parameters { "date": "2025-07-04T06:44:33.014Z" } ``` Select will return the first item that returns true. So the first condition uses `defined()` to check if `$date` is not `null` 1. Query again without a `date` value ```json:Parameters { "date": null } ``` Otherwise, it returns `true` which will have no impact on the filter because all documents satisfy the condition. Note that a parameter cannot be `undefined`, so if you declare a parameter in a query which could be missing, it must be present in the supplied parameters as `null`.