A shim patches an API with functionality that isn’t available in the environment. If your code is running in an old environment, you may use a shim to get access to newer features within the environment. However, those features would need to be re-implemented with the building blocks provided within the old environment.
In other words, shim is the more general term. While polyfill is a shim within a browser context.
Read more on: