Web Development Web Development 2 — Questions and Answers
Question 1: Which HTTP status code indicates that a resource has been permanently moved to a new URL?
- 301 Moved Permanently (Correct answer)
- 302 Found
- 304 Not Modified
- 307 Temporary Redirect
Correct answer: 301 Moved Permanently
301 Moved Permanently tells clients and search engines to update their links to the new URL.
Question 2: In CSS Flexbox, which property controls the alignment of items along the cross axis?
- justify-content
- align-items (Correct answer)
- flex-direction
- flex-wrap
Correct answer: align-items
align-items controls how flex children are aligned along the cross axis (perpendicular to the main axis).
Question 3: What does the 'defer' attribute do when added to a <script> tag?
- Loads the script asynchronously and executes immediately
- Downloads the script in parallel and executes after HTML parsing completes (Correct answer)
- Prevents the script from loading until user interaction
- Executes the script before DOM construction begins
Correct answer: Downloads the script in parallel and executes after HTML parsing completes
The defer attribute downloads the script without blocking HTML parsing and runs it after the document is fully parsed.
Question 4: Which JavaScript method creates a shallow copy of an array?
- Array.from(arr)
- arr.slice()
- arr.concat([])
- All of the above (Correct answer)
Correct answer: All of the above
Array.from(), slice(), and concat([]) all produce a new shallow copy of the original array.
Question 5: In REST API design, which HTTP method is idempotent but NOT safe?
- GET
- DELETE (Correct answer)
- POST
- HEAD
Correct answer: DELETE
DELETE is idempotent (same result if called multiple times) but not safe because it modifies server state.
Question 6: What is the purpose of a Content Security Policy (CSP) header?
- Compress HTTP responses for faster delivery
- Restrict sources from which content can be loaded to prevent XSS (Correct answer)
- Encrypt data in transit between client and server
- Cache static assets at the CDN edge
Correct answer: Restrict sources from which content can be loaded to prevent XSS
CSP headers tell browsers which content sources are trusted, reducing the risk of cross-site scripting attacks.
Question 7: Which CSS unit is relative to the font-size of the root element?
- em
- rem (Correct answer)
- vh
- ex
Correct answer: rem
rem (root em) is always relative to the font-size set on the <html> element, unlike em which is relative to the parent.
Which HTTP status code indicates that a resource has been permanently moved to a new URL?