Web Development Web Development 4 — Questions and Answers
Question 1: What is CORS and why is it enforced by browsers?
- A caching strategy that stores assets locally
- A security mechanism that restricts cross-origin HTTP requests made from scripts (Correct answer)
- A compression format for web fonts
- A protocol for real-time browser-to-browser communication
Correct answer: A security mechanism that restricts cross-origin HTTP requests made from scripts
CORS (Cross-Origin Resource Sharing) is a browser security policy that blocks scripts from making requests to a different origin unless the server explicitly allows it.
Question 2: In JavaScript, what is the output of: typeof null?
- 'null'
- 'undefined'
- 'object' (Correct answer)
- 'boolean'
Correct answer: 'object'
typeof null returns 'object' — a well-known historical bug in JavaScript that has been kept for backward compatibility.
Question 3: Which web performance metric measures the time until a page's main content is visually rendered?
- Time to First Byte (TTFB)
- Largest Contentful Paint (LCP) (Correct answer)
- Cumulative Layout Shift (CLS)
- First Input Delay (FID)
Correct answer: Largest Contentful Paint (LCP)
LCP measures how long it takes for the largest visible content element (image or text block) to fully render in the viewport.
Question 4: What does the CSS 'box-sizing: border-box' declaration change?
- Adds a visible border outline around the element
- Includes padding and border within the element's declared width and height (Correct answer)
- Removes the default margin from block elements
- Sets the element to use absolute positioning
Correct answer: Includes padding and border within the element's declared width and height
With border-box, padding and border are included inside the element's specified width/height instead of being added on top.
Question 5: In version control with Git, what does 'git rebase' do compared to 'git merge'?
- Rebase deletes the source branch; merge keeps it
- Rebase replays commits onto a new base, creating a linear history; merge creates a merge commit (Correct answer)
- Rebase is faster; merge is safer for production
- Rebase only works locally; merge works with remote branches
Correct answer: Rebase replays commits onto a new base, creating a linear history; merge creates a merge commit
Git rebase moves commits to a new base commit, producing a cleaner linear history, while merge preserves the branch topology with a merge commit.
Question 6: Which JavaScript feature allows you to extract values from arrays and objects into distinct variables in a single statement?
- Spread operator
- Destructuring assignment (Correct answer)
- Template literals
- Optional chaining
Correct answer: Destructuring assignment
Destructuring assignment syntax lets you unpack values from arrays or properties from objects into separate variables concisely.
Question 7: What is the main advantage of using a CDN (Content Delivery Network) for static assets?
- CDNs provide server-side rendering for dynamic content
- Assets are served from edge servers geographically closer to users, reducing latency (Correct answer)
- CDNs handle database queries to reduce server load
- CDNs automatically fix broken links and 404 errors
Correct answer: Assets are served from edge servers geographically closer to users, reducing latency
CDNs cache and serve static files from distributed edge locations worldwide, minimizing the physical distance data must travel to reach users.
What is CORS and why is it enforced by browsers?