Listing examples with や
List a few examples without claiming to name the whole set.

Learn
Like と, や joins nouns, but や presents them as examples from a larger set. 本 や ペン means “books, pens, and other things” or “things such as books and pens.”
English can make this clear with “such as” or “among other things.” Japanese expresses it through や between the nouns, so you do not always need to spell out “and other things” in a natural English translation.
Choose や when you intend to give examples. 犬 や 猫 が 好き です says you like animals such as dogs and cats. と is also grammatical, but presents dogs and cats as the particular set you are naming.
Examples
机 の 上 に 本 や ペン が あります。
There are books, pens, and other things on the desk.
犬 や 猫 が 好き です。
I like animals such as dogs and cats.
公園 や 図書館 に 行きます。
I go to places such as parks and libraries.