Web Programming Web Programming 3 — Questions and Answers
Question 1: What is the difference between '==' and '===' in JavaScript?
- There is no difference
- === checks value only, == checks type only
- == allows type coercion, === checks both value and type strictly (Correct answer)
- === is used only for strings
Correct answer: == allows type coercion, === checks both value and type strictly
== performs type coercion before comparing, while === checks both value and type without conversion.
Question 2: In HTML, what attribute makes a form field required before submission?
- mandatory
- validate
- required (Correct answer)
- notempty
Correct answer: required
The 'required' attribute on an input element triggers browser validation to prevent form submission if the field is empty.
Question 3: What is the purpose of a CSS media query?
- Loads different CSS files per browser
- Applies styles based on device characteristics like screen width (Correct answer)
- Fetches media files from external URLs
- Controls video and audio element styling
Correct answer: Applies styles based on device characteristics like screen width
Media queries apply CSS rules conditionally based on device features such as viewport width, enabling responsive design.
Question 4: Which HTTP method is typically used to UPDATE an existing resource in a REST API?
- GET
- POST
- PUT (Correct answer)
- DELETE
Correct answer: PUT
PUT replaces an existing resource with the provided data; PATCH is used for partial updates.
Question 5: What does the 'async' keyword do when added to a JavaScript function?
- Runs the function in a separate thread
- Makes the function always return a Promise (Correct answer)
- Disables error handling in the function
- Forces the function to run synchronously
Correct answer: Makes the function always return a Promise
An async function always returns a Promise and enables the use of 'await' inside it to pause execution until a Promise resolves.
Question 6: In CSS Grid, what does 'grid-template-columns: repeat(3, 1fr)' create?
- 3 rows of equal height
- 3 columns of equal width that share available space (Correct answer)
- A grid with 3-pixel columns
- 3 fixed columns of 100px each
Correct answer: 3 columns of equal width that share available space
repeat(3, 1fr) creates three equal-width columns that each take one fraction of the available grid space.
Question 7: Which JavaScript method converts a JSON string into a JavaScript object?
- JSON.stringify()
- JSON.parse() (Correct answer)
- JSON.convert()
- JSON.decode()
Correct answer: JSON.parse()
JSON.parse() takes a JSON-formatted string and returns the corresponding JavaScript object or value.
What is the difference between '==' and '===' in JavaScript?