Practice Questions
-
Asynchronous JavaScript (Callbacks, Promises, Async/Await)
-
Write a function
greetUser(name, callback)that prints a greeting and then calls the callback function. -
Create a promise that resolves after 3 seconds with a message
"Data loaded successfully". Handle it using.then()and.catch(). -
Rewrite the same promise using async/await and print the result.
-
APIs & Fetch
-
Use
fetch()to get data fromhttps://jsonplaceholder.typicode.com/postsand display titles of first 5 posts in console. -
Handle errors using
try…catchwhile fetching data.
-
Classes & Objects
-
Create a class
Carwith propertiesbrandandmodeland a methoddisplayInfo(). Create 2 objects of this class and call the method for both. -
Extend the
Carclass with a subclassElectricCarthat adds a propertybatteryLife. Demonstrate inheritance.
-
Error Handling
-
Write a function
divide(a, b)that throws an error ifbis zero. Handle it usingtry…catch. -
Create a form validation script that throws an error if input fields are empty.
-
Modules & Import/Export
-
Create a module
mathUtils.jsthat exports functionsadd(a,b)andmultiply(a,b). Import them in another file and use them.
-
Advanced ES6+ Features
-
Use array destructuring to extract first two elements from
[10, 20, 30, 40]. -
Use object destructuring to extract
nameandagefrom{name: "Raman", age: 25, city: "Delhi"}. -
Use spread operator to merge two arrays
[1,2]and[3,4]. -
Use rest operator in a function
sum(...numbers)to add all numbers passed as arguments. -
Use optional chaining to safely access a nested property
user.address.citywhenaddressmay not exist.
✅ Summary:
-
Practice covers asynchronous JavaScript, API calls, classes, error handling, modules, and modern ES6 features.
-
Students should write, run, and debug code to understand each concept deeply.
-
Prepares students for real-world web development scenarios.
