Web Programming Web Programming 4 — Questions and Answers
Question 1: What is 'hoisting' in JavaScript?
- Moving scripts to the top of the HTML file
- JavaScript's behavior of moving declarations to the top of their scope before execution (Correct answer)
- Uploading files to a web server
- Optimizing scripts for faster loading
Correct answer: JavaScript's behavior of moving declarations to the top of their scope before execution
Hoisting moves variable and function declarations to the top of their scope during the compilation phase, before code runs.
Question 2: Which CSS pseudo-class targets the first child element of its parent?
- :root
- :first-of-type
- :first-child (Correct answer)
- :nth-child(0)
Correct answer: :first-child
:first-child selects an element only if it is the first child of its parent, regardless of element type.
Question 3: What is the role of a 'package.json' file in a Node.js project?
- Stores the compiled application bundle
- Lists project metadata, dependencies, and scripts (Correct answer)
- Contains the server's SSL certificate
- Defines HTML templates for the project
Correct answer: Lists project metadata, dependencies, and scripts
package.json is the project manifest that tracks dependencies, scripts, version, and other metadata for Node.js projects.
Question 4: In a RESTful API, what does a 404 status code response indicate?
- Server error occurred
- Authentication is required
- The requested resource was not found (Correct answer)
- The request was successful
Correct answer: The requested resource was not found
404 Not Found means the server could not locate the resource at the requested URL.
Question 5: What is the purpose of the 'z-index' property in CSS?
- Sets the zoom level of the element
- Controls the stacking order of positioned elements on the z-axis (Correct answer)
- Defines the element's position in the document flow
- Sets the opacity of the element
Correct answer: Controls the stacking order of positioned elements on the z-axis
z-index controls which overlapping element appears on top by defining its position along the z-axis (depth).
Question 6: Which HTML element is the correct semantic container for the main navigation links of a website?
- <div id='nav'>
- <section>
- <nav> (Correct answer)
- <menu>
Correct answer: <nav>
The <nav> element is the semantic HTML5 element specifically designed to wrap major navigation link groups.
Question 7: What is 'event bubbling' in JavaScript?
- Creating multiple events simultaneously
- An event propagating from the target element up through its parent elements (Correct answer)
- Events firing before the DOM is loaded
- Animations triggered by user events
Correct answer: An event propagating from the target element up through its parent elements
Event bubbling means an event triggered on a child element propagates upward through ancestor elements in the DOM tree.
What is 'hoisting' in JavaScript?