JavaScript Practical Test (15 Questions)
Topics Covered:
JS Variables
JS Operators
JS If Conditions
JS Loops
JS Strings
JS Numbers
JS Functions
JS Objects
JS Scope
JS Dates
JS Arrays
JS Sets
JS Maps
JS Iterations
JS Math
JS RegExp
JS Data Types
Q1) Variables + Data Types
Create variables using let, const, var:
- name (string)
- age (number)
- isOnline (boolean)
- city (string)
Print each value + its type using typeof.
Q2) Operators
Given:
let a = 15;
let b = 4;
Print:
- a+b
- a-b
- a*b
- a/b
- a%b
Q3) If Conditions
Write a program to check:
- If number is positive → print "Positive"
- If negative → print "Negative"
- Else → print "Zero"
Q4) Loops
Print all even numbers from 1 to 50 using a loop.
Q5) Strings
Given:
let str = " JavaScript is Awesome ";
Do the following:
1. Remove spaces from start and end
2. Convert to uppercase
3. Print length
Q6) Numbers
Take:
let price = "499.99";
Convert it into a number and print:
- value as number
- value after rounding using [Link]()
Q7) Functions
Create a function calculator(x, y, operator) which performs:
- "+" addition
- "-" subtraction
- "*" multiplication
- "/" division
Return the result.
Q8) Arrays
Create an array:
let arr = [10, 20, 30, 40, 50];
Perform:
1. Add 60 at the end
2. Remove first element
3. Print updated array
Q9) Iterations (forEach / map)
Using the array:
let nums = [2, 4, 6, 8];
1. Print each number using forEach()
2. Create a new array of squares using map()
Q10) Objects
Create an object student with:
- name
- rollNo
- marks
Print:
1. student name using dot notation
2. all keys using [Link]()
3. all values using [Link]()
Q11) Scope
Write a program to show difference between var, let, const inside a block { }.
Try printing them outside the block and observe output.
Q12) Dates
Create a Date object for current date/time and print:
- Full date
- Current year
- Current month
- Current day
Q13) Sets
From this array:
let data = [1, 2, 2, 3, 4, 4, 5];
Convert it into a Set to remove duplicates and print final unique values.
Q14) Maps
Create a Map named userInfo and store:
- "name" → "Rahul"
- "email" → "rahul@[Link]"
- "age" → 24
Print all values using .get() and also print size using .size.
Q15) RegExp
Write a program to validate:
A password must contain at least 1 number.
Examples:
- "abc" → invalid
- "abc123" → valid
Use RegExp and print "Valid Password" or "Invalid Password".