Front End Development Front-End Development Course 3 — Questions and Answers
Question 1: Which JavaScript method returns a new array with only the elements that pass a test function?
- filter() (Correct answer)
- map()
- reduce()
- find()
Correct answer: filter()
filter() creates a new array containing all elements for which the callback returns a truthy value.
Question 2: What is the purpose of the `alt` attribute on an `<img>` tag?
- Provides alternative text for accessibility and when the image fails to load (Correct answer)
- Sets the image title shown on hover
- Links the image to a caption
- Specifies the image file format
Correct answer: Provides alternative text for accessibility and when the image fails to load
The alt attribute supplies descriptive text for screen readers and displays as fallback text when the image cannot be rendered.
Question 3: Which CSS unit is relative to the font size of the root element?
- rem (Correct answer)
- em
- vh
- px
Correct answer: rem
rem (root em) is always relative to the font size of the <html> element, making it predictable unlike em which cascades.
Question 4: In JavaScript, which statement correctly declares a block-scoped variable?
- let x = 5; (Correct answer)
- var x = 5;
- global x = 5;
- define x = 5;
Correct answer: let x = 5;
let declares a variable with block scope, meaning it is only accessible within the enclosing {} block.
Question 5: What does CORS stand for in web development?
- Cross-Origin Resource Sharing (Correct answer)
- Client-Origin Request Security
- Cross-Object Response System
- Content-Origin Rendering Standard
Correct answer: Cross-Origin Resource Sharing
CORS is a browser security mechanism that controls how web pages can request resources from a different domain than the one that served the page.
Question 6: Which CSS property makes an element invisible but still occupies space in the layout?
- visibility: hidden (Correct answer)
- display: none
- opacity: 0 with pointer-events: none
- position: absolute
Correct answer: visibility: hidden
visibility: hidden hides an element visually while it continues to occupy its original space in the document flow.
Question 7: Which JavaScript event fires when the DOM is fully parsed but before images and stylesheets finish loading?
- DOMContentLoaded (Correct answer)
- load
- readystatechange
- beforeunload
Correct answer: DOMContentLoaded
DOMContentLoaded fires as soon as the HTML is parsed and the DOM tree is ready, without waiting for external resources.
Which JavaScript method returns a new array with only the elements that pass a test function?