-
Which semantic HTML element is most appropriate for a group of navigation links?
- <section>
- <nav>
- <aside>
- <ul>
Correct Answer: <nav>
Explanation: The <nav> element is specifically designed to contain navigation links to improve accessibility and SEO.
-
In CSS Flexbox, which property is used to align items along the main axis?
- align-items
- align-content
- justify-content
- flex-direction
Correct Answer: justify-content
Explanation: The justify-content property defines how the browser distributes space between and around content items along the main axis of a flex container.
-
What is the result of '2' + 2 in JavaScript?
Correct Answer: 22
Explanation: In JavaScript, using the '+' operator with a string and a number triggers type coercion, resulting in string concatenation.
-
Which HTTP method is considered 'idempotent', meaning multiple identical requests have the same effect as a single request?
- POST
- PATCH
- GET
- All of the above
Correct Answer: GET
Explanation: GET, PUT, and DELETE are idempotent. POST is not because multiple requests will likely result in multiple resource creations.
-
What does the 'defer' attribute do when included in a <script> tag?
- Executes the script immediately
- Downloads the script in parallel and executes after the document is parsed
- Stops HTML parsing until the script is downloaded
- Prevents the script from running
Correct Answer: Downloads the script in parallel and executes after the document is parsed
Explanation: The 'defer' attribute ensures the script is executed only after the HTML document has been fully parsed, without blocking the initial render.
-
In CSS, what is the default value of the 'position' property?
- relative
- absolute
- fixed
- static
Correct Answer: static
Explanation: Elements are positioned 'static' by default, meaning they follow the normal document flow.
-
What is a closure in JavaScript?
- A way to close the browser tab
- A function that has access to its outer function's scope even after the outer function has returned
- A method to delete variables
- A syntax for ending a loop
Correct Answer: A function that has access to its outer function's scope even after the outer function has returned
Explanation: A closure is the combination of a function bundled together with references to its surrounding state (lexical environment).
-
Which CSS property is used to change the stack order of elements?
- float
- z-index
- display
- overflow
Correct Answer: z-index
Explanation: The z-index property specifies the stack order of an element that has a position value other than static.
-
In Node.js, what is the purpose of 'package.json'?
- To store binary data
- To serve as the entry point of the app
- To manage project dependencies and metadata
- To compile JavaScript to Machine Code
Correct Answer: To manage project dependencies and metadata
Explanation: The package.json file holds metadata relevant to the project and is used for managing dependencies, scripts, and versions.
-
What is the correct syntax for a CSS variable?
- $variable-name
- var-variable-name
- --variable-name
- @variable-name
Correct Answer: --variable-name
Explanation: CSS Custom Properties (variables) are defined using two dashes as a prefix, like --main-color.
-
Which JavaScript method is used to create a new array with all elements that pass a specific test?
- map()
- forEach()
- filter()
- reduce()
Correct Answer: filter()
Explanation: The filter() method creates a shallow copy of a portion of a given array, filtered down to just the elements that pass the test.
-
What does the 'box-sizing: border-box' CSS property do?
- Adds padding to the outside of the element
- Includes padding and border in the element's total width and height
- Prevents the element from having a border
- Forces the element to be a square
Correct Answer: Includes padding and border in the element's total width and height
Explanation: Border-box tells the browser to account for any border and padding in the values you specify for an element's width and height.
-
Which of the following is NOT a valid state of a JavaScript Promise?
- Pending
- Fulfilled
- Rejected
- Waiting
Correct Answer: Waiting
Explanation: A Promise is in one of these states: pending (initial state), fulfilled (completed successfully), or rejected (failed).
-
In a RESTful API, which HTTP status code represents a successful creation of a resource?
- 200 OK
- 201 Created
- 204 No Content
- 400 Bad Request
Correct Answer: 201 Created
Explanation: 201 Created is the standard response for a successful POST request that results in a resource being created.
-
What is the purpose of the 'alt' attribute in an <img> tag?
- To provide a link to the image
- To specify the image size
- To provide alternative text for screen readers and if the image fails to load
- To apply CSS styles
Correct Answer: To provide alternative text for screen readers and if the image fails to load
Explanation: The alt attribute is critical for accessibility, allowing screen readers to describe the image to visually impaired users.
-
How do you select an element with the id 'header' in CSS?
- .header
- header
- #header
- *header
Correct Answer: #header
Explanation: The '#' symbol is used as the ID selector in CSS.
-
Which keyword is used to declare a block-scoped variable that cannot be reassigned?
Correct Answer: const
Explanation: The 'const' keyword creates a read-only reference to a value, and it is block-scoped.
-
What does 'Event Delegation' refer to in JavaScript?
- Assigning an event listener to every child element
- Using a single event listener on a parent element to manage events for its children
- Deleting events after they occur
- Stopping events from bubbling
Correct Answer: Using a single event listener on a parent element to manage events for its children
Explanation: Event delegation takes advantage of event bubbling by adding a single listener to a parent instead of multiple listeners to children.
-
Which CSS Grid property defines the size of the gaps between rows and columns?
- spacing
- grid-margin
- gap
- grid-padding
Correct Answer: gap
Explanation: The 'gap' property (shorthand for row-gap and column-gap) defines the size of the gutters between grid items.
-
What is the 'Same-Origin Policy'?
- A policy that allows any website to access your cookies
- A security measure that restricts how a document or script loaded from one origin can interact with a resource from another origin
- A rule that requires all websites to use HTTPS
- A method for caching website data
Correct Answer: A security measure that restricts how a document or script loaded from one origin can interact with a resource from another origin
Explanation: The Same-Origin Policy (SOP) is a critical security mechanism that isolates potentially malicious documents, reducing possible attack vectors.