Module 4: Practice Questions
Bhai, ye questions aise diye gaye hain ki student khud solve kare aur concepts ko practice kare.
Practice Questions
-
Variables & Data Types
-
Declare a variable
usernameand assign your name to it. -
Create a variable
ageand store your age. -
Print both values in the console.
-
Functions & Scope
-
Write a function
greetUserthat takes a name as input and prints"Hello, <name>!". -
Create a local variable inside the function and try to access it outside. What happens?
-
Arrays & Objects
-
Create an array
fruitswith 5 fruits. Add a new fruit at the end and remove the first one. -
Create an object
studentwith keys:name,age,grade. Change thegradeproperty.
-
Conditional Statements & Loops
-
Write a program to check if a number is even or odd.
-
Create a loop that prints numbers from 1 to 20.
-
Write a
for…ofloop to print all items of an array of your choice.
-
DOM Basics
-
Select an element with id
headingand change its text content to"Welcome!". -
Select all paragraphs and log their text content to the console.
-
Selecting & Manipulating Elements
-
Change the background color of a div with class
boxto green. -
Add a new paragraph dynamically inside a container div.
-
Event Handling
-
Create a button. On click, change the button text to
"Clicked!". -
Add an
inputfield. Show the typed text below the input in real time.
-
Form Validation
-
Create a form with
usernameandemailfields. Validate that fields are not empty. -
Validate that the email is in correct format using regex.
-
ES6 Features
-
Write an arrow function that takes two numbers and returns their sum.
-
Use template literals to print your name and age in a single string.
-
Use destructuring to extract values from an array
[10, 20, 30].
-
LocalStorage & SessionStorage
-
Store your name in LocalStorage and retrieve it.
-
Store your session start time in SessionStorage and display it.
-
JSON
-
Create a JSON object with your name, age, and hobbies.
-
Convert it to string using
JSON.stringify()and then parse it back to object usingJSON.parse().
✅ Summary:
-
Module 4 practice focuses on JavaScript fundamentals, DOM, events, ES6 features, and storage.
-
Students should write code, run it in browser, and understand outputs.
