Gotcha.
Well let me give you a quick explanation. Your system uses the available system memory (RAM) as a holding area for things being operated on by the OS or applications. This is transient and meant to be temporary. Anything permanent goes to the storage (HDD, SSD, etc.).
When you have a machine with limited system memory but lots of demands from many applications running, the OS needs to "augment" this memory somehow. There are many different ways of doing this. One option in the more recent versions of macOS is to compress data in system memory that hasn't been accessed recently but know will be. That makes room for other data to be stored.
But this doesn't work in every situation and there will come a time when there isn't enough system memory to fulfill the requests from applications, so the OS will "swap" out the old data to storage to make space. However, it's entirely possible that the swapped out data could be asked for at any time and it's expensive to load it from scratch like was done initially. So, rather, the OS basically dumps out a number of pages of data as it was sitting in memory to a file it wholly controls and that's the swap file. That way, when the future request comes in, it can reload those swapped out pages quickly back into memory and it's ready to go without any additional work.
Where you end up with issues is when you are running on a system with very little memory, say 4GB of memory and have apps (like photo/video editing) that want large files loaded. Since there isn't enough system memory available to accommodate this, the OS will constantly swap in and out the pieces of data it needs to make the app work and beat up on the storage at the same time.
If you look at Activity Monitor and depending on the version of OS, if you see high Swap In/Out or Swap Used values, then you are in a situation where your machine could benefit from more memory based on your workflow.
Additionally, since the swap file is sitting on your storage, if you run low on storage with other data, you end up with REALLY bad performance to crashes since the OS can't swap anything to the storage but the demands of memory are constantly being made.
Hope that helps.