Lesson 8 of 30
The browser blocks your own JavaScript from reading responses from a different origin by default — CORS is the server's explicit permission slip that opts back in, selectively.
12 min read
Every option explains itself — why the right one is right, and why each wrong one is wrong. Miss one and it comes back later on a spaced-repetition schedule.
Question 1 of 2
A cross-origin request fails with a CORS error in the browser console. Did the server ever actually receive and process the request?
Hints without spoilers, and a plain explanation of why a wrong answer was wrong — answered only from this lesson. Free account, no card.
Sign up freeWhat interviewers actually ask about this, and what a strong answer has to cover.
A strong answer covers
Likely follow-ups
The same-origin policy is a browser security default: JavaScript running on https://app.com cannot read the response of a request to https://api.other.com unless that other server explicitly allows it. "Origin" means the exact combination of scheme + host + port — https://app.com and http://app.com are different origins; so are app.com and api.app.com.
CORS (Cross-Origin Resource Sharing) is the server opting back in, via response headers:
Access-Control-Allow-Origin: https://app.com
Without this header (or the wrong value), the browser still lets the request go out and the server still processes it — but the browser blocks your JavaScript from reading the response. This is a common point of confusion: CORS is not a firewall stopping the request; it's the browser withholding the response from your code.
fetch('https://api.other-site.com') from your page — the browser blocks the response by default. Different origin.
Access-Control-Allow-Origin: * can't be combined with credentials (cookies, Authorization headers) — sending credentials cross-origin requires an exact origin match in the header, not a wildcard, for real security reasons (a wildcard plus credentials would let any site read authenticated responses).Access-Control-Allow-Origin on the server, not anything the frontend code can work around on its own (short of a proxy)."Why am I getting a CORS error, and what actually causes it?" is one of the most common real debugging questions frontend developers hit — correctly explaining that it's the browser withholding the response, not the server refusing the request, is the precise distinction that separates understanding from guessing.