Fetching JSON with fetch() — JS Technical Interview Questions & Answers
Requesting and parsing JSON from an API.
Fetching JSON with fetch()
- Fetching JSON with fetch() is a JS topic. In plain words you use it for GET /api/marks in the browser. Don’t start with a slogan — start with that picture.
- Smallest example: fetch + await + try/catch. Type it, run it, and say what you see. If you can do that from memory, you know Fetching JSON with fetch().
- From the example next to this theory: Requesting and parsing JSON from an API.
- Trap: no catch → silent fail. Fix that before you talk about advanced JS.
- Viva: what is Fetching JSON with fetch()? Then show fetch + await + try/catch. Then name the trap.
Technical Interview Tip: What is Fetching JSON with fetch()? Show this: fetch + await + try/catch. Trap: no catch → silent fail.
Code Examples for Fetching JSON with fetch()
Fetching JSON with fetch() — working example
const user = { name: "Ada", skills: ["JS", "SQL"] };
const raw = JSON.stringify(user);
const back = JSON.parse(raw);
console.log(raw);
console.log(back.name, back.skills.length);
// fetch sketch (lab uses parse stand-in):
async function load() {
const data = JSON.parse('{"ok":true}');
return data.ok;
}
load().then(console.log);Fetching JSON with fetch() — jSON is text; stringify/parse convert to plain data. fetch() loads JSON from APIs in the browser/Node.
How to Explain Fetching JSON with fetch() to an Interviewer
What is Fetching JSON with fetch()?
Used for GET /api/marks the browser Not just the heading
Give one small example of Fetching JSON with fetch().
fetch + await + try/catch Requesting and parsing JSON from an API
What mistake do beginners make with Fetching JSON with fetch()?
no catch → silent fail Show the fix
Where do you use Fetching JSON with fetch()?
the browser GET /api/marks