Web Programming Web Programming 2 — Questions and Answers
Question 1: Which HTTP status code indicates a resource was permanently moved to a new URL?
- 200 OK
- 301 Moved Permanently (Correct answer)
- 404 Not Found
- 500 Internal Server Error
Correct answer: 301 Moved Permanently
301 Moved Permanently tells clients and search engines the resource has a new permanent URL.
Question 2: In CSS, what does the 'box-sizing: border-box' property do?
- Adds a border around all elements
- Includes padding and border in the element's total width and height (Correct answer)
- Sets the border color to the box's background color
- Makes the element a block-level container
Correct answer: Includes padding and border in the element's total width and height
border-box makes the width/height include padding and border, so the element doesn't grow beyond the set size.
Question 3: What is the purpose of the JavaScript 'event.preventDefault()' method?
- Stops the event from firing
- Prevents the browser's default action for the event (Correct answer)
- Removes all event listeners from the element
- Bubbles the event to the parent element
Correct answer: Prevents the browser's default action for the event
preventDefault() stops the browser's built-in behavior, like preventing a form from submitting or a link from navigating.
Question 4: Which SQL clause is used to filter results after aggregation?
- WHERE
- FILTER
- HAVING (Correct answer)
- LIMIT
Correct answer: HAVING
HAVING filters grouped/aggregated results, whereas WHERE filters rows before grouping.
Question 5: What does CORS stand for in web development?
- Cross-Origin Resource Sharing (Correct answer)
- Content Object Rendering System
- Client-Origin Request Security
- Cross-Origin Request Specification
Correct answer: Cross-Origin Resource Sharing
CORS is a browser security mechanism that controls how web pages can request resources from a different domain.
Question 6: In React, what hook is used to perform side effects in a functional component?
- useState
- useRef
- useEffect (Correct answer)
- useCallback
Correct answer: useEffect
useEffect runs side effects like data fetching, subscriptions, or DOM updates after the component renders.
Question 7: Which property in CSS creates a flexible container for its children?
- display: block
- display: flex (Correct answer)
- position: relative
- float: left
Correct answer: display: flex
display: flex activates the Flexbox layout model, making the element a flex container for its direct children.
Which HTTP status code indicates a resource was permanently moved to a new URL?