How CORS (Cross-Origin Resource Sharing) Works?

How CORS (Cross-Origin Resource Sharing) Works?

If you are a web developer, you must have seen the ‘CORS’ error appearing often on your screen when you try to call the API. But, Why does it happen?