Now, let's move to the next topic in the Web Development Roadmap:
π HTTP vs HTTPS (Internet Basics π)
π§ What is HTTP?
π HTTP = HyperText Transfer Protocol
- Used to transfer data between browser β server
- Not secure β
- Data is sent in plain text
π‘ Example:
If you enter password β it can be intercepted π¬
π What is HTTPS?
π HTTPS = Secure version of HTTP
- Uses SSL/TLS encryption
- Data is encrypted π
- Safe for:
- Payments π³
- Logins π
π‘ Example:
Even if someone intercepts β they canβt read data
βοΈ Key Difference (Must Remember)
Security
- HTTP: β Not secure
- HTTPS: β Secure
Encryption
- HTTP: β No
- HTTPS: β Yes
URL
- HTTP: http://
- HTTPS: https://
Use case
- HTTP: Basic sites
- HTTPS: Login, banking
π How to Identify HTTPS?
π Look at browser address bar:
- π Lock icon = Secure
- No lock = Not safe
β‘ Real-Life Example
π Think like sending a message:
- HTTP = Normal message (anyone can read)
- HTTPS = Locked message (only receiver can read)
π What is SSL/TLS?
- Itβs a security layer
- Encrypts data between browser & server
π Thatβs why HTTPS is safe
π― Mini Task
1. Open any website
2. Check URL:
- Starts with https?
- Lock icon visible?
π Try both secure & non-secure sites
π‘ HTTPS ensures secure communication using encryption (SSL/TLS)
Double Tap β€οΈ For More
π HTTP vs HTTPS (Internet Basics π)
π§ What is HTTP?
π HTTP = HyperText Transfer Protocol
- Used to transfer data between browser β server
- Not secure β
- Data is sent in plain text
π‘ Example:
If you enter password β it can be intercepted π¬
π What is HTTPS?
π HTTPS = Secure version of HTTP
- Uses SSL/TLS encryption
- Data is encrypted π
- Safe for:
- Payments π³
- Logins π
π‘ Example:
Even if someone intercepts β they canβt read data
βοΈ Key Difference (Must Remember)
Security
- HTTP: β Not secure
- HTTPS: β Secure
Encryption
- HTTP: β No
- HTTPS: β Yes
URL
- HTTP: http://
- HTTPS: https://
Use case
- HTTP: Basic sites
- HTTPS: Login, banking
π How to Identify HTTPS?
π Look at browser address bar:
- π Lock icon = Secure
- No lock = Not safe
β‘ Real-Life Example
π Think like sending a message:
- HTTP = Normal message (anyone can read)
- HTTPS = Locked message (only receiver can read)
π What is SSL/TLS?
- Itβs a security layer
- Encrypts data between browser & server
π Thatβs why HTTPS is safe
π― Mini Task
1. Open any website
2. Check URL:
- Starts with https?
- Lock icon visible?
π Try both secure & non-secure sites
π‘ HTTPS ensures secure communication using encryption (SSL/TLS)
Double Tap β€οΈ For More
JavaScript Interview Practice Questions (Logic Building Test)
Section A β If-Else & Basic Logic
Q1.
Find the largest number in the given array without using Math.max().
Q2.
Count the even and odd numbers present in an array.
Q3.
Check whether a given string is a Palindrome or not.
Q4.
Find the second largest number in an array without sorting it.
Q5.
Calculate the factorial of a given number.
Section B β Loops (for, while, do...while)
Q6.
Print all numbers from 1 to 100 using a for loop.
Q7.
Print all even numbers between 1 and 100.
Q8.
Print all odd numbers between 1 and 100.
Q9.
Print the multiplication table of a given number.
Q10.
Print the Fibonacci Series up to n terms.
Q11.
Print all prime numbers between 1 and 100.
Q12.
Reverse a given string using a loop.
Q13.
Reverse an array without using the .reverse() method.
Q14.
Print numbers from 10 to 1 using a while loop.
Q15.
Write a program using a do...while loop that executes at least one time even if the condition is false.
Section C β Switch Case
Q16.
Display the name of the day based on a number (1β7) using switch.
Q17.
Create a simple calculator using switch (+, -, *, /).
Q18.
Display the month name based on the month number (1β12).
Section D β Arrays
Q19.
Find the sum of all elements in an array.
Q20.
Find the smallest number in an array.
Q21.
Find the largest number in an array.
Q22.
Find all duplicate elements in an array.
Q23.
Remove duplicate elements from an array.
Q24.
Count how many times each element appears in an array.
Q25.
Find the missing number from an array containing numbers from 1 to n.
Q26.
Merge two arrays without duplicate values.
Q27.
Find the intersection of two arrays.
Q28.
Move all zero values to the end of an array.
Q29.
Rotate an array by one position.
Q30.
Sort an array in ascending order without using .sort().
Section A β If-Else & Basic Logic
Q1.
Find the largest number in the given array without using Math.max().
Q2.
Count the even and odd numbers present in an array.
Q3.
Check whether a given string is a Palindrome or not.
Q4.
Find the second largest number in an array without sorting it.
Q5.
Calculate the factorial of a given number.
Section B β Loops (for, while, do...while)
Q6.
Print all numbers from 1 to 100 using a for loop.
Q7.
Print all even numbers between 1 and 100.
Q8.
Print all odd numbers between 1 and 100.
Q9.
Print the multiplication table of a given number.
Q10.
Print the Fibonacci Series up to n terms.
Q11.
Print all prime numbers between 1 and 100.
Q12.
Reverse a given string using a loop.
Q13.
Reverse an array without using the .reverse() method.
Q14.
Print numbers from 10 to 1 using a while loop.
Q15.
Write a program using a do...while loop that executes at least one time even if the condition is false.
Section C β Switch Case
Q16.
Display the name of the day based on a number (1β7) using switch.
Q17.
Create a simple calculator using switch (+, -, *, /).
Q18.
Display the month name based on the month number (1β12).
Section D β Arrays
Q19.
Find the sum of all elements in an array.
Q20.
Find the smallest number in an array.
Q21.
Find the largest number in an array.
Q22.
Find all duplicate elements in an array.
Q23.
Remove duplicate elements from an array.
Q24.
Count how many times each element appears in an array.
Q25.
Find the missing number from an array containing numbers from 1 to n.
Q26.
Merge two arrays without duplicate values.
Q27.
Find the intersection of two arrays.
Q28.
Move all zero values to the end of an array.
Q29.
Rotate an array by one position.
Q30.
Sort an array in ascending order without using .sort().
Section E β Array Methods
Q31.
Use the map() method to create a new array containing the square of each number.
Q32.
Use the filter() method to extract only even numbers from an array.
Q33.
Use the reduce() method to calculate the sum of all array elements.
Q34.
Check whether a particular value exists in an array using array methods.
Q35.
Convert an array into a comma-separated string.
Section F β Strings
Q36.
Count the number of vowels in a string.
Q37.
Count the frequency of each character in a string.
Q38.
Find the longest word in a sentence.
Q39.
Check whether two strings are Anagrams.
Q40.
Reverse every word in a sentence.
Section G β Objects
Q41.
Print all keys and values of an object using for...in.
Q42.
Count the total number of properties in an object.
Q43.
Merge two objects into one object.
Q44.
Check whether a given property exists in an object.
Q45.
Convert an object into an array of keys.
Q46.
Convert an object into an array of values.
Q47.
Find the property with the highest value in an object.
Section H β Mixed Interview Logic
Q48.
Count the number of positive, negative, and zero values in an array.
Q49.
Find the maximum occurring element in an array.
Q50.
Write a program to display the following pattern:
*
**
***
****
*
Q51.
Wr
*
****
***
**
*
Q52.
W
*
***
*
***
1
12
123
1234
12345
Q54.
Wr
5
54
543
5432
54321
Name : Rah
Q31.
Use the map() method to create a new array containing the square of each number.
Q32.
Use the filter() method to extract only even numbers from an array.
Q33.
Use the reduce() method to calculate the sum of all array elements.
Q34.
Check whether a particular value exists in an array using array methods.
Q35.
Convert an array into a comma-separated string.
Section F β Strings
Q36.
Count the number of vowels in a string.
Q37.
Count the frequency of each character in a string.
Q38.
Find the longest word in a sentence.
Q39.
Check whether two strings are Anagrams.
Q40.
Reverse every word in a sentence.
Section G β Objects
Q41.
Print all keys and values of an object using for...in.
Q42.
Count the total number of properties in an object.
Q43.
Merge two objects into one object.
Q44.
Check whether a given property exists in an object.
Q45.
Convert an object into an array of keys.
Q46.
Convert an object into an array of values.
Q47.
Find the property with the highest value in an object.
Section H β Mixed Interview Logic
Q48.
Count the number of positive, negative, and zero values in an array.
Q49.
Find the maximum occurring element in an array.
Q50.
Write a program to display the following pattern:
*
**
***
****
*
Q51.
Wr
ite a program to display the following pattern:*
****
***
**
*
Q52.
W
rite a program to display the following pattern:*
***
*
***
*********
Q53.
Write a program to display the following pattern:1
12
123
1234
12345
Q54.
Wr
ite a program to display the following pattern:5
54
543
5432
54321
Q55.
Create a student object and display all student details in the following format:Name : Rah
ul
Age : 22
Course : MERN Stack
City : Indore
Ye 55 questions beginner se intermediate aur interview-oriented level ke hain. Inme if-else, switch, for, while, do...while, for...of, for...in, arrays, array methods, strings, objects aur logic building sab cover ho jata hai.https://youtu.be/vCyA5RSvi2I?si=maEYG2fTbYfz3dzf
is video ke comment section me jo mene test diya eh 50 question ka sections wise uski answersheet me ncihe de rahi hu .
JavaScript Test β Answer Sheet
Section A (Output Based)
Q1
Output:
Explanation: ++a pehle increment karta hai (11), a++ current value (11) use karke baad me increment karta hai. Final a = 12, b = 11 + 11 = 22.
Q2
Output:
Explanation: x++ returns 20, then x becomes 21. ++x makes it 22. Result = 20 + 22 = 42.
Q3
Output:
Explanation: 10 + "5" becomes "105" (string concatenation), then "105" - 2 = 103.
Q4
Output:
Explanation: typeof null returns "object" due to a historical JavaScript bug.
Q5
Output:
Explanation: Arrays are special types of objects, so typeof [] returns "object".
Q6
Output:
Explanation: trim() removes spaces and toUpperCase() converts all characters to uppercase.
Q7
Output:
Explanation: slice(0,9) returns characters from index 0 to 8.
Q8
Output:
Explanation: substring(4,10) returns characters from index 4 to 9.
Q9
Output:
Explanation: repeat(2) repeats the string twice.
Q10
Output:
Explanation: split(",") converts the string into an array using comma as the separator.
Q11
Output:
Explanation: push(40) adds 40; pop() immediately removes the last element.
Q12
Output:
Explanation: slice(1,3) returns elements from index 1 up to (but not including) index 3.
Q13
Output:
Explanation: splice(1,1,10) removes one element at index 1 and inserts 10.
Q14
Output:
Explanation: includes(20) checks whether 20 exists in the array.
Q15
Output:
Explanation: Every element is even, so every() returns true.
Q16
Output:
Explanation: 3 is greater than 2, so some() returns true.
Q17
Output:
Explanation: Object.keys() returns an array of all object keys.
Q18
Output:
Explanation: delete obj.name removes the name property, leaving an empty object.
Q19
Output:
Explanation: Object.freeze() prevents modification of existing properties, so a remains 10.
Q20
Output:
Explanation: 5 > 10 is false, so the ternary operator returns "No".
β Final Answer Key (Quick Checking)
SECTION : A
Q.No Answer
1) 12 22
2) 42
3) 103
4) "object"
5) "object"
6) JAVASCRIPT
7) Knowledge
8) Script
9) HelloHello
10) ["apple","banana","mango"]
11) [10,20,30]
12) [2,3]
13) [1,10,3]
14) true
15) true
16) true
17) ["name","city"]
18) {}
19) 10
20) No
is video ke comment section me jo mene test diya eh 50 question ka sections wise uski answersheet me ncihe de rahi hu .
JavaScript Test β Answer Sheet
Section A (Output Based)
Q1
Output:
12 22Explanation: ++a pehle increment karta hai (11), a++ current value (11) use karke baad me increment karta hai. Final a = 12, b = 11 + 11 = 22.
Q2
Output:
42Explanation: x++ returns 20, then x becomes 21. ++x makes it 22. Result = 20 + 22 = 42.
Q3
Output:
103Explanation: 10 + "5" becomes "105" (string concatenation), then "105" - 2 = 103.
Q4
Output:
objectExplanation: typeof null returns "object" due to a historical JavaScript bug.
Q5
Output:
objectExplanation: Arrays are special types of objects, so typeof [] returns "object".
Q6
Output:
JAVASCRIPTExplanation: trim() removes spaces and toUpperCase() converts all characters to uppercase.
Q7
Output:
KnowledgeExplanation: slice(0,9) returns characters from index 0 to 8.
Q8
Output:
ScriptExplanation: substring(4,10) returns characters from index 4 to 9.
Q9
Output:
HelloHelloExplanation: repeat(2) repeats the string twice.
Q10
Output:
["apple", "banana", "mango"]Explanation: split(",") converts the string into an array using comma as the separator.
Q11
Output:
[10, 20, 30]Explanation: push(40) adds 40; pop() immediately removes the last element.
Q12
Output:
[2, 3]Explanation: slice(1,3) returns elements from index 1 up to (but not including) index 3.
Q13
Output:
[1, 10, 3]Explanation: splice(1,1,10) removes one element at index 1 and inserts 10.
Q14
Output:
trueExplanation: includes(20) checks whether 20 exists in the array.
Q15
Output:
trueExplanation: Every element is even, so every() returns true.
Q16
Output:
trueExplanation: 3 is greater than 2, so some() returns true.
Q17
Output:
["name", "city"]Explanation: Object.keys() returns an array of all object keys.
Q18
Output:
{}Explanation: delete obj.name removes the name property, leaving an empty object.
Q19
Output:
10Explanation: Object.freeze() prevents modification of existing properties, so a remains 10.
Q20
Output:
NoExplanation: 5 > 10 is false, so the ternary operator returns "No".
β Final Answer Key (Quick Checking)
SECTION : A
Q.No Answer
1) 12 22
2) 42
3) 103
4) "object"
5) "object"
6) JAVASCRIPT
7) Knowledge
8) Script
9) HelloHello
10) ["apple","banana","mango"]
11) [10,20,30]
12) [2,3]
13) [1,10,3]
14) true
15) true
16) true
17) ["name","city"]
18) {}
19) 10
20) No
YouTube
JavaScript Core Fundamentals in 5 Hours! | Datatypes, Arrays, Objects, Strings & Operators (Part 1)
Welcome to Part 1 of the Ultimate JavaScript Masterclass! π
In this massive 5-hour comprehensive tutorial, we are diving deep into the absolute core fundamentals of JavaScript. Whether you are a beginner or brushing up on your concepts, this video coversβ¦
In this massive 5-hour comprehensive tutorial, we are diving deep into the absolute core fundamentals of JavaScript. Whether you are a beginner or brushing up on your concepts, this video coversβ¦
JavaScript Test β Answer Sheet
---->>> Section B β Theory Questions (21β35)
Q21. Differentiate between var, let and const.
Answer:
var , let, const
Function scoped , Block scoped , Block scoped
Can be redeclared , Cannot be redeclared, Cannot be redeclared
Can be reassigned , Can be reassigned , Cannot be reassigned
Hoisted and initialized with undefined, Hoisted but in Temporal Dead Zone , Hoisted but in Temporal Dead Zone
Explanation:
var is the old way of declaring variables. let is used when the value may change, and const is used for values that should not be reassigned.
Q22. What is the difference between == and ===?
Answer:
== (Loose Equality) compares only values and performs type conversion if needed.
=== (Strict Equality) compares both value and data type without type conversion.
Example:
Explanation:
Always prefer === because it gives more accurate comparisons.
Q23. Explain pre-increment and post-increment with an example.
Answer:
Pre-increment (++a) increases the value before it is used.
Post-increment (a++) uses the current value first and then increases it.
Example:
Explanation:
The main difference is when the increment happens.
Q24. What is the purpose of the typeof operator?
Answer:
The typeof operator is used to determine the data type of a variable or value.
Example:
Explanation:
It helps identify the type of data stored in a variable.
Q25. What is the difference between slice() and substring()?
Answer:
slice(), substring()
Supports negative indexes , Does not support negative indexes
Does not swap indexes, Swaps indexes if start > end
Explanation:
Both return a part of a string, but slice() is more flexible because it supports negative indexing.
Q26. Differentiate between splice() and slice().
Answer:
splice(), slice()
Changes the original array, Does not change the original array
Used to add/remove elements, Used to copy a portion of an array
Returns removed elements, Returns a new array
Explanation:
splice() modifies the original array, whereas slice() creates a new array.
Q27. What is the difference between push() and unshift()?
Answer:
push() adds element(s) at the end of an array.
unshift() adds element(s) at the beginning of an array.
Example:
Explanation:
Both methods add elements, but at different positions.
Q28. Differentiate between pop() and shift().
Answer:
pop() removes the last element from an array.
shift() removes the first element from an array.
Explanation:
Both remove one element, but from opposite ends of the array.
Q29. Explain the difference between map() and forEach().
Answer:
map() , forEach()
Returns a new array, Does not return a new array (returns undefined)
Used for transformation, Used for iteration
Original array remains unchanged, Original array remains unchanged unless modified manually
Explanation:
Use map() when you need a transformed array. Use forEach() when you only want to perform an action on each element.
Q30. Differentiate between filter() and find().
Answer:
filter(), find()
Returns all matching elements, Returns only the first matching element
Returns an array, Returns a single value or undefined
Explanation:
Use filter() for multiple results and find() when only the first match is required.
Q31. What is the use of the reduce() method?
Answer:
reduce() is used to reduce an array into a single value by applying a callback function to each element.
Example:
Explanation:
It is commonly used for calculating sums, products, averages, and other aggregated values.
---->>> Section B β Theory Questions (21β35)
Q21. Differentiate between var, let and const.
Answer:
var , let, const
Function scoped , Block scoped , Block scoped
Can be redeclared , Cannot be redeclared, Cannot be redeclared
Can be reassigned , Can be reassigned , Cannot be reassigned
Hoisted and initialized with undefined, Hoisted but in Temporal Dead Zone , Hoisted but in Temporal Dead Zone
Explanation:
var is the old way of declaring variables. let is used when the value may change, and const is used for values that should not be reassigned.
Q22. What is the difference between == and ===?
Answer:
== (Loose Equality) compares only values and performs type conversion if needed.
=== (Strict Equality) compares both value and data type without type conversion.
Example:
5 == "5" // true
5 === "5" // falseExplanation:
Always prefer === because it gives more accurate comparisons.
Q23. Explain pre-increment and post-increment with an example.
Answer:
Pre-increment (++a) increases the value before it is used.
Post-increment (a++) uses the current value first and then increases it.
Example:
let a = 5;
console.log(++a); // 6
let b = 5;
console.log(b++); // 5
console.log(b); // 6Explanation:
The main difference is when the increment happens.
Q24. What is the purpose of the typeof operator?
Answer:
The typeof operator is used to determine the data type of a variable or value.
Example:
typeof 10 // "number"
typeof "Hello" // "string"
typeof true // "boolean"
typeof undefined // "undefined"
typeof [] // "object"Explanation:
It helps identify the type of data stored in a variable.
Q25. What is the difference between slice() and substring()?
Answer:
slice(), substring()
Supports negative indexes , Does not support negative indexes
Does not swap indexes, Swaps indexes if start > end
Explanation:
Both return a part of a string, but slice() is more flexible because it supports negative indexing.
Q26. Differentiate between splice() and slice().
Answer:
splice(), slice()
Changes the original array, Does not change the original array
Used to add/remove elements, Used to copy a portion of an array
Returns removed elements, Returns a new array
Explanation:
splice() modifies the original array, whereas slice() creates a new array.
Q27. What is the difference between push() and unshift()?
Answer:
push() adds element(s) at the end of an array.
unshift() adds element(s) at the beginning of an array.
Example:
arr.push(5);
arr.unshift(1);Explanation:
Both methods add elements, but at different positions.
Q28. Differentiate between pop() and shift().
Answer:
pop() removes the last element from an array.
shift() removes the first element from an array.
Explanation:
Both remove one element, but from opposite ends of the array.
Q29. Explain the difference between map() and forEach().
Answer:
map() , forEach()
Returns a new array, Does not return a new array (returns undefined)
Used for transformation, Used for iteration
Original array remains unchanged, Original array remains unchanged unless modified manually
Explanation:
Use map() when you need a transformed array. Use forEach() when you only want to perform an action on each element.
Q30. Differentiate between filter() and find().
Answer:
filter(), find()
Returns all matching elements, Returns only the first matching element
Returns an array, Returns a single value or undefined
Explanation:
Use filter() for multiple results and find() when only the first match is required.
Q31. What is the use of the reduce() method?
Answer:
reduce() is used to reduce an array into a single value by applying a callback function to each element.
Example:
let arr = [1,2,3];
let sum = arr.reduce((acc, curr) => acc + curr, 0);Explanation:
It is commonly used for calculating sums, products, averages, and other aggregated values.
Q32. Differentiate between Object.freeze() and Object.seal().
Answer:
Object.freeze() Object.seal()
Cannot add, delete, or modify properties Cannot add or delete properties, but existing properties can still be
Explanation:
freeze() makes an object completely immutable, whereas seal() partially restricts changes.
Q33. Explain the purpose of Object.keys(), Object.values(), and Object.entries().
Answer:
Object.keys() returns an array of all property names (keys).
Object.values() returns an array of all property values.
Object.entries() returns an array of key-value pairs.
Example:
Object.keys(obj) β ["name", "age"]
Object.values(obj) β ["Payal", 22]
Object.entries(obj) β [["name","Payal"],["age",22]]
Explanation:
These methods are commonly used to access and iterate over object data.
Q34. What is Array Destructuring? Explain with an example.
Answer:
Array Destructuring is a feature that allows values from an array to be assigned directly to variables.
Example:
Explanation:
Instead of accessing elements using indexes, destructuring provides a cleaner and shorter syntax.
Q35. What is the Spread Operator? Explain with an example.
Answer:
The Spread Operator (...) is used to expand elements of an array or properties of an object.
Example:
Explanation:
It is commonly used for copying arrays or objects, merging arrays or objects, and passing multiple values to functions.
β Quick Checking Key
Q.No) Expected Answer
21) Difference between var, let, const
22) == vs ===
23) Pre-increment vs Post-increment
24) Purpose of typeof
25) slice() vs substring()
26) splice() vs slice()
27) push() vs unshift()
28) pop() vs shift()
29) map() vs forEach()
30) filter() vs find()
31) Use of reduce()
32) Object.freeze() vs Object.seal()
33) Object.keys(), Object.values(), Object.entries()
34) Array Destructuring
35) Spread Operator (...)
Note: Q32 ka answer ek important correction ke saath diya gaya hai: Object.seal() existing properties ko modify karne deta hai sirf tab jab woh properties writable hon. Ye JavaScript ka actual behavior hai aur interview point of view se bhi accurate answer hai.
Answer:
Object.freeze() Object.seal()
Cannot add, delete, or modify properties Cannot add or delete properties, but existing properties can still be
Explanation:
freeze() makes an object completely immutable, whereas seal() partially restricts changes.
Q33. Explain the purpose of Object.keys(), Object.values(), and Object.entries().
Answer:
Object.keys() returns an array of all property names (keys).
Object.values() returns an array of all property values.
Object.entries() returns an array of key-value pairs.
Example:
const obj = {
name: "Payal",
age: 22
};Object.keys(obj) β ["name", "age"]
Object.values(obj) β ["Payal", 22]
Object.entries(obj) β [["name","Payal"],["age",22]]
Explanation:
These methods are commonly used to access and iterate over object data.
Q34. What is Array Destructuring? Explain with an example.
Answer:
Array Destructuring is a feature that allows values from an array to be assigned directly to variables.
Example:
let arr = [10,20,30];
let [a,b,c] = arr;Explanation:
Instead of accessing elements using indexes, destructuring provides a cleaner and shorter syntax.
Q35. What is the Spread Operator? Explain with an example.
Answer:
The Spread Operator (...) is used to expand elements of an array or properties of an object.
Example:
let arr1 = [1,2,3];
let arr2 = [...arr1,4,5];Explanation:
It is commonly used for copying arrays or objects, merging arrays or objects, and passing multiple values to functions.
β Quick Checking Key
Q.No) Expected Answer
21) Difference between var, let, const
22) == vs ===
23) Pre-increment vs Post-increment
24) Purpose of typeof
25) slice() vs substring()
26) splice() vs slice()
27) push() vs unshift()
28) pop() vs shift()
29) map() vs forEach()
30) filter() vs find()
31) Use of reduce()
32) Object.freeze() vs Object.seal()
33) Object.keys(), Object.values(), Object.entries()
34) Array Destructuring
35) Spread Operator (...)
Note: Q32 ka answer ek important correction ke saath diya gaya hai: Object.seal() existing properties ko modify karne deta hai sirf tab jab woh properties writable hon. Ye JavaScript ka actual behavior hai aur interview point of view se bhi accurate answer hai.
JavaScript Test β Answer Sheet
---->>> Section C β Interview Based Questions (36β45)
Q36. What is the difference between Primitive and Reference Data Types?
Answer:
Primitive Data Types Reference Data Types
Store the actual value Store the memory reference (address)
Copied by value Copied by reference
Immutable Mutable (objects and arrays can be modified)
Primitive Types: Number, String, Boolean, Undefined, Null, BigInt, Symbol
Reference Types: Object, Array, Function
Explanation:
Primitive variables store the actual value, while reference variables store the address of the object in memory.
Q37. What is the difference between indexOf() and includes()?
Answer:
indexOf() includes()
Returns the index of the element Returns true or false
Returns -1 if not found Returns false if not found
Example:
Explanation:
Use indexOf() when you need the position of an element and includes() when you only need to check its existence.
Q38. Why does typeof null return "object"?
Answer:
typeof null returns "object" because of a historical bug in JavaScript. This behavior has been preserved for backward compatibility and cannot be changed without breaking existing code.
Explanation:
Although null represents the intentional absence of a value, JavaScript still reports its type as "object".
Q39. When should we use const instead of let?
Answer:
Use const when the variable should not be reassigned after its initial declaration.
Use let when the variable's value needs to change later in the program.
Explanation:
Using const helps prevent accidental reassignment and makes the code more predictable and easier to maintain.
Q40. Explain the difference between Object.assign() and structuredClone().
Answer:
Object.assign() structuredClone()
Creates a shallow copy Creates a deep copy
Nested objects are shared Nested objects are copied independently
Suitable for simple objects Suitable for complex nested objects
Explanation:
Use Object.assign() for shallow cloning and structuredClone() when a true deep copy of an object is required.
Q41. What is the difference between hasOwnProperty() and the in operator?
Answer:
hasOwnProperty() in operator
Checks only the object's own properties Checks both own and inherited properties
Does not check the prototype chain Checks the prototype chain as well
Example:
Explanation:
Use hasOwnProperty() to verify that a property belongs directly to the object. Use the in operator to check whether a property exists anywhere in the object's prototype chain.
Q42. What is the difference between sort() and reverse()?
Answer:
sort() reverse()
Arranges elements in a specified/default order Reverses the current order of elements
Changes the original array Changes the original array
Explanation:
sort() is used for sorting values, whereas reverse() simply reverses the existing order of elements.
Q43. Explain instanceof with an example.
Answer:
The instanceof operator checks whether an object is an instance of a particular constructor or class.
Example:
Explanation:
It returns true if the object's prototype chain contains the constructor's prototype; otherwise, it returns false.
Q44. What is the difference between Object.create() and object literals ({})?
Answer:
Object.create() Object Literal ({})
Creates a new object with a specified prototype Creates a normal object with Object.prototype as its prototype
Allows custom prototype inheritance Uses the default prototype
Explanation:
Object.create() is useful when you want to control an object's prototype, while {} is the standard and most common way to create objects.
---->>> Section C β Interview Based Questions (36β45)
Q36. What is the difference between Primitive and Reference Data Types?
Answer:
Primitive Data Types Reference Data Types
Store the actual value Store the memory reference (address)
Copied by value Copied by reference
Immutable Mutable (objects and arrays can be modified)
Primitive Types: Number, String, Boolean, Undefined, Null, BigInt, Symbol
Reference Types: Object, Array, Function
Explanation:
Primitive variables store the actual value, while reference variables store the address of the object in memory.
Q37. What is the difference between indexOf() and includes()?
Answer:
indexOf() includes()
Returns the index of the element Returns true or false
Returns -1 if not found Returns false if not found
Example:
let arr = [10,20,30];
arr.indexOf(20); // 1
arr.includes(20); // trueExplanation:
Use indexOf() when you need the position of an element and includes() when you only need to check its existence.
Q38. Why does typeof null return "object"?
Answer:
typeof null returns "object" because of a historical bug in JavaScript. This behavior has been preserved for backward compatibility and cannot be changed without breaking existing code.
Explanation:
Although null represents the intentional absence of a value, JavaScript still reports its type as "object".
Q39. When should we use const instead of let?
Answer:
Use const when the variable should not be reassigned after its initial declaration.
Use let when the variable's value needs to change later in the program.
Explanation:
Using const helps prevent accidental reassignment and makes the code more predictable and easier to maintain.
Q40. Explain the difference between Object.assign() and structuredClone().
Answer:
Object.assign() structuredClone()
Creates a shallow copy Creates a deep copy
Nested objects are shared Nested objects are copied independently
Suitable for simple objects Suitable for complex nested objects
Explanation:
Use Object.assign() for shallow cloning and structuredClone() when a true deep copy of an object is required.
Q41. What is the difference between hasOwnProperty() and the in operator?
Answer:
hasOwnProperty() in operator
Checks only the object's own properties Checks both own and inherited properties
Does not check the prototype chain Checks the prototype chain as well
Example:
obj.hasOwnProperty("name");
"name" in obj;Explanation:
Use hasOwnProperty() to verify that a property belongs directly to the object. Use the in operator to check whether a property exists anywhere in the object's prototype chain.
Q42. What is the difference between sort() and reverse()?
Answer:
sort() reverse()
Arranges elements in a specified/default order Reverses the current order of elements
Changes the original array Changes the original array
Explanation:
sort() is used for sorting values, whereas reverse() simply reverses the existing order of elements.
Q43. Explain instanceof with an example.
Answer:
The instanceof operator checks whether an object is an instance of a particular constructor or class.
Example:
let arr = [1,2,3];
arr instanceof Array; // true
arr instanceof Object; // trueExplanation:
It returns true if the object's prototype chain contains the constructor's prototype; otherwise, it returns false.
Q44. What is the difference between Object.create() and object literals ({})?
Answer:
Object.create() Object Literal ({})
Creates a new object with a specified prototype Creates a normal object with Object.prototype as its prototype
Allows custom prototype inheritance Uses the default prototype
Explanation:
Object.create() is useful when you want to control an object's prototype, while {} is the standard and most common way to create objects.
Q45. What is the purpose of JSON.stringify() and JSON.parse()?
Answer:
JSON.stringify() converts a JavaScript object into a JSON string.
JSON.parse() converts a JSON string back into a JavaScript object.
Example:
let obj = {
name: "Payal"
};
let json =
JSON.stringify(obj);
let data = JSON.parse(json);Explanation:
These methods are commonly used for data storage, API communication, and converting objects into a transferable format.
β Quick Checking Key
Q.No Expected Answer
36 Primitive vs Reference Data Types
37 indexOf() vs includes()
38 Why typeof null is "object"
39 When to use const instead of let
40 Object.assign() vs structuredClone()
41 hasOwnProperty() vs in operator
42 sort() vs reverse()
43 instanceof operator
44 Object.create() vs {}
45 JSON.stringify() vs JSON.parse()
Accuracy Note: Is answer sheet me diye gaye concepts JavaScript ke standard behavior ke according hain. Q40 (shallow vs deep copy), Q41 (prototype chain), Q43 (instanceof), aur Q44 (prototype inheritance) interview me frequently puche jaate hain, isliye unke explanations bhi interview-standard level ke rakhe gaye hain.
JavaScript Test β Answer Sheet
---->>> Section D β Practical / Coding Questions (46β50)
Q46. Write a program to count the number of even and odd elements present in an array.
Answer
Explanation
Traverse the array using a loop.
Check each element using % 2.
Increase the even or odd counter accordingly.
Q47. Write a program to remove duplicate values from an array without using any external library.
Answer
Explanation
Create an empty array.
Check whether the current element already exists using includes().
If not, add it to the new array.
Q48. Write a program to merge two arrays using the Spread Operator.
Answer
Explanation
The spread operator (...) expands all elements of both arrays into a new array.
Q49. Write a program to clone an object using:
Object.assign()
structuredClone()
Answer
Using Object.assign()
Using structuredClone()
Explanation
Object.assign() creates a shallow copy.
structuredClone() creates a deep copy.
Q50. Create an object named student containing name, course, and marks. Print:
all keys,
all values,
all key-value pairs,
using the appropriate Object methods.
Answer
Output
]
Explanation
Object.keys() returns all property names.
Object.values() returns all property values.
Object.entries() returns all key-value pairs as nested arrays.
β Quick Checking Key
Q.No Expected Logic
46 Count even and odd numbers using loop and condition
47 Remove duplicates using includes() and a new array
48 Merge arrays using the spread operator (...)
49 Clone object using Object.assign() and structuredClone()
50 Use Object.keys(), Object.values(), and Object.entries() on a student object
π Checking Notes (for Teacher)
Q46: Accept any loop (for, while, for...of, etc.) if the even/odd count is correct.
Q47: Students may use includes(), indexOf(), or nested loops. Any correct duplicate-removal logic is acceptable.
Q48: The expected solution uses the spread operator (...), as requested in the question.
Q49: Both cloning methods should be demonstrated separately. Students should know that Object.assign() performs a shallow copy, while structuredClone() performs a deep copy.
Q50: Students must correctly use Object.keys(), Object.values(), and Object.entries(). The object values (name, course, marks) may differ, but the methods used should be correct.
---->>> Section D β Practical / Coding Questions (46β50)
Q46. Write a program to count the number of even and odd elements present in an array.
Answer
let arr = [10, 15, 20, 25, 30, 35];
let evenCount = 0;
let oddCount = 0;
for (let i = 0; i < arr.length; i++) {
if (arr[i] % 2 === 0) {
evenCount++;
} else {
oddCount++;
}
}
console.log("Even Numbers :", evenCount);
console.log("Odd Numbers :", oddCount);Explanation
Traverse the array using a loop.
Check each element using % 2.
Increase the even or odd counter accordingly.
Q47. Write a program to remove duplicate values from an array without using any external library.
Answer
let arr = [10, 20, 30, 20, 40, 10, 50];
let uniqueArr = [];
for (let i = 0; i < arr.length; i++) {
if (!uniqueArr.includes(arr[i])) {
uniqueArr.push(arr[i]);
}
}
console.log(uniqueArr);Explanation
Create an empty array.
Check whether the current element already exists using includes().
If not, add it to the new array.
Q48. Write a program to merge two arrays using the Spread Operator.
Answer
let arr1 = [10, 20, 30];
let arr2 = [40, 50, 60];
let mergedArray = [...arr1, ...arr2];
console.log(mergedArray);Explanation
The spread operator (...) expands all elements of both arrays into a new array.
Q49. Write a program to clone an object using:
Object.assign()
structuredClone()
Answer
Using Object.assign()
let student = {
name: "Payal",
age: 22
};
let copy1 = Object.assign({}, student);
console.log(copy1);Using structuredClone()
let copy2 = structuredClone(student);
console.log(copy2);Explanation
Object.assign() creates a shallow copy.
structuredClone() creates a deep copy.
Q50. Create an object named student containing name, course, and marks. Print:
all keys,
all values,
all key-value pairs,
using the appropriate Object methods.
Answer
let student = {
name: "Payal",
course: "JavaScript",
marks: 95
};
console.log(Object.keys(student));
console.log(Object.values(student));
console.log(Object.entries(student));Output
["name", "course", "marks"]
["Payal", "JavaScript", 95]
[
["name", "Payal"],
["course", "JavaScript"],
["marks", 95]]
Explanation
Object.keys() returns all property names.
Object.values() returns all property values.
Object.entries() returns all key-value pairs as nested arrays.
β Quick Checking Key
Q.No Expected Logic
46 Count even and odd numbers using loop and condition
47 Remove duplicates using includes() and a new array
48 Merge arrays using the spread operator (...)
49 Clone object using Object.assign() and structuredClone()
50 Use Object.keys(), Object.values(), and Object.entries() on a student object
π Checking Notes (for Teacher)
Q46: Accept any loop (for, while, for...of, etc.) if the even/odd count is correct.
Q47: Students may use includes(), indexOf(), or nested loops. Any correct duplicate-removal logic is acceptable.
Q48: The expected solution uses the spread operator (...), as requested in the question.
Q49: Both cloning methods should be demonstrated separately. Students should know that Object.assign() performs a shallow copy, while structuredClone() performs a deep copy.
Q50: Students must correctly use Object.keys(), Object.values(), and Object.entries(). The object values (name, course, marks) may differ, but the methods used should be correct.
Inventory_Management_API_Assessment.pdf
2.6 KB
Inventory_Management_API_Assessment.pdf
JavaScript Test - Section A Answer Key
Output Based Questions with Short Explanation
Q1
}
Output
Explanation
20 >= 18 is true.
Therefore, the if block executes.
Q2
}
Output
Explanation
72 >= 90 β False
72 >= 75 β False
72 >= 60 β True β
So "C" is printed and the remaining conditions are skipped.
Q3
}
Output
Explanation
day is 3.
It matches case 3.
"Wednesday" is printed.
break exits the switch.
Q4
}
Output
Explanation
Loop starts from 1.
Runs while i <= 5.
After each iteration, i increases by 1.
Q5
}
Output
Explanation
The loop starts with i = 1.
It continues while i <= 4.
i is incremented after every iteration.
Q6
Output
Explanation
do...while executes the block once before checking the condition.
It prints 5.
Then i becomes 6.
6 <= 4 is false, so the loop stops.
Q7
}
Output
Explanation
1 is printed.
2 is printed.
When i becomes 3, break immediately terminates the loop.
So 3, 4, and 5 are not printed.
Q8
}
Output
Explanation
continue skips only the current iteration.
When i = 3, console.log() is skipped.
The loop continues with 4 and 5.
Q9
}
Output
Explanation
for...in iterates over the property names (keys) of an object.
It prints name, age, and city.
Q10
}
Output
Explanation
for...of iterates over the values of an iterable.
It prints each array element one by one.
Summary Table :
Q. No. Output
1. Adult
2. C
3. Wednesday
4. 1 2 3 4 5
5. 1 2 3 4
6. 5
7. 1 2
8. 1 2 4 5
9. name age city
10. Red Green Blue
This answer key is suitable for checking this test
Output Based Questions with Short Explanation
Q1
let age = 20;
if (age >= 18) {
console.log("Adult");
} else {
console.log("Minor");}
Output
Adult
Explanation
20 >= 18 is true.
Therefore, the if block executes.
Q2
let marks = 72;
if (marks >= 90) {
console.log("A");
}
else if (marks >= 75) {
console.log("B");
}
else if (marks >= 60) {
console.log("C");
}
else {
console.log("Fail");}
Output
C
Explanation
72 >= 90 β False
72 >= 75 β False
72 >= 60 β True β
So "C" is printed and the remaining conditions are skipped.
Q3
let day = 3;
switch(day){
case 1:
console.log("Monday");
break;
case 2:
console.log("Tuesday");
break;
case 3:
console.log("Wednesday");
break;
default:
console.log("Invalid");}
Output
Wednesday
Explanation
day is 3.
It matches case 3.
"Wednesday" is printed.
break exits the switch.
Q4
for(let i=1; i<=5; i++){
console.log(i);}
Output
1
2
3
4
5
Explanation
Loop starts from 1.
Runs while i <= 5.
After each iteration, i increases by 1.
Q5
let i = 1;
while(i<=4){
console.log(i);
i++;}
Output
1
2
3
4
Explanation
The loop starts with i = 1.
It continues while i <= 4.
i is incremented after every iteration.
Q6
let i = 5;
do{
console.log(i);
i++;
}
while(i<=4);Output
5
Explanation
do...while executes the block once before checking the condition.
It prints 5.
Then i becomes 6.
6 <= 4 is false, so the loop stops.
Q7
for(let i=1;i<=5;i++){
if(i==3){
break;
}
console.log(i);}
Output
1
2
Explanation
1 is printed.
2 is printed.
When i becomes 3, break immediately terminates the loop.
So 3, 4, and 5 are not printed.
Q8
for(let i=1;i<=5;i++){
if(i==3){
continue;
}
console.log(i);}
Output
1
2
4
5
Explanation
continue skips only the current iteration.
When i = 3, console.log() is skipped.
The loop continues with 4 and 5.
Q9
let student = {
name:"Payal",
age:22,
city:"Indore"
};
for(let key in student){
console.log(key);}
Output
name
age
city
Explanation
for...in iterates over the property names (keys) of an object.
It prints name, age, and city.
Q10
let colors = ["Red","Green","Blue"];
for(let color of colors){
console.log(color);}
Output
Red
Green
Blue
Explanation
for...of iterates over the values of an iterable.
It prints each array element one by one.
Summary Table :
Q. No. Output
1. Adult
2. C
3. Wednesday
4. 1 2 3 4 5
5. 1 2 3 4
6. 5
7. 1 2
8. 1 2 4 5
9. name age city
10. Red Green Blue
This answer key is suitable for checking this test
JavaScript Test β Section B Answer Key :
Logical Programming Questions with Short Explanation
Q1. Print numbers from 1 to 20 using a for loop.
Answer
}
Explanation
The loop starts from 1.
It runs until i <= 20.
After every iteration, i increases by 1.
Q2. Print all even numbers from 1 to 30.
Answer
}
Explanation
% gives the remainder.
If a number is divisible by 2 (i % 2 === 0), it is an even number.
Q3. Print all odd numbers from 1 to 20.
Answer
}
Explanation
Odd numbers leave a remainder of 1 when divided by 2.
Therefore, we check i % 2 !== 0.
Q4. Check whether a number is Positive, Negative, or Zero.
Answer
}
Explanation
If the number is greater than 0, it is Positive.
If it is less than 0, it is Negative.
Otherwise, it is Zero.
Q5. Check whether a number is Even or Odd.
Answer
}
Explanation
Even numbers are divisible by 2.
If the remainder is 0, print "Even".
Otherwise, print "Odd".
Q6. Print the month name using a switch statement.
Answer
}
Explanation
switch compares the value of month with each case.
When a match is found, the corresponding month name is printed.
break prevents execution of the remaining cases.
Q7. Print numbers from 10 to 1 using a while loop.
Answer
}
Explanation
The loop starts from 10.
It continues while i >= 1.
After each iteration, i decreases by 1.
Q8. Print numbers from 1 to 5 using a do...while loop.
Answer
Explanation
do...while executes the code block first.
Then it checks the condition.
The loop continues until i becomes greater than 5.
Q9. Print all property names of the object using for...in.
Answer
}
Output
Explanation
for...in loops through the keys (property names) of an object.
It prints name, age, and course.
Q10. Print every fruit using for...of.
Answer
}
Output
Explanation
for...of loops through the values of an array.
It prints each fruit one by one.
--------------------------------------------------------------------------
Quick Answer Summary :
Question Topic Key Concept
Q1 for Loop Print numbers 1β20
Q2 for + if Print even numbers
Q3 for + if Print odd numbers
Q4 if...else if...else Positive, Negative, Zero
Q5 if...else Even or Odd
Q6 switch Month Name
Q7 while Loop Print 10 to 1
Q8 do...while Loop Print 1 to 5
Q9 for...in Print object keys
Q10 for...of Print array values
This answer key is ideal for beginners, with straightforward solutions that use only the concepts covered in this lessons and brief
Logical Programming Questions with Short Explanation
Q1. Print numbers from 1 to 20 using a for loop.
Answer
for (let i = 1; i <= 20; i++) {
console.log(i);}
Explanation
The loop starts from 1.
It runs until i <= 20.
After every iteration, i increases by 1.
Q2. Print all even numbers from 1 to 30.
Answer
for (let i = 1; i <= 30; i++) {
if (i % 2 === 0) {
console.log(i);
}}
Explanation
% gives the remainder.
If a number is divisible by 2 (i % 2 === 0), it is an even number.
Q3. Print all odd numbers from 1 to 20.
Answer
for (let i = 1; i <= 20; i++) {
if (i % 2 !== 0) {
console.log(i);
}}
Explanation
Odd numbers leave a remainder of 1 when divided by 2.
Therefore, we check i % 2 !== 0.
Q4. Check whether a number is Positive, Negative, or Zero.
Answer
let num = -5;
if (num > 0) {
console.log("Positive");
}
else if (num < 0) {
console.log("Negative");
}
else {
console.log("Zero");}
Explanation
If the number is greater than 0, it is Positive.
If it is less than 0, it is Negative.
Otherwise, it is Zero.
Q5. Check whether a number is Even or Odd.
Answer
let num = 15;
if (num % 2 === 0) {
console.log("Even");
}
else {
console.log("Odd");}
Explanation
Even numbers are divisible by 2.
If the remainder is 0, print "Even".
Otherwise, print "Odd".
Q6. Print the month name using a switch statement.
Answer
let month = 4;
switch (month) {
case 1:
console.log("January");
break;
case 2:
console.log("February");
break;
case 3:
console.log("March");
break;
case 4:
console.log("April");
break;
case 5:
console.log("May");
break;
case 6:
console.log("June");
break;
case 7:
console.log("July");
break;
case 8:
console.log("August");
break;
case 9:
console.log("September");
break;
case 10:
console.log("October");
break;
case 11:
console.log("November");
break;
case 12:
console.log("December");
break;
default:
console.log("Invalid Month");}
Explanation
switch compares the value of month with each case.
When a match is found, the corresponding month name is printed.
break prevents execution of the remaining cases.
Q7. Print numbers from 10 to 1 using a while loop.
Answer
let i = 10;
while (i >= 1) {
console.log(i);
i--;}
Explanation
The loop starts from 10.
It continues while i >= 1.
After each iteration, i decreases by 1.
Q8. Print numbers from 1 to 5 using a do...while loop.
Answer
let i = 1;
do {
console.log(i);
i++;
}
while (i <= 5);Explanation
do...while executes the code block first.
Then it checks the condition.
The loop continues until i becomes greater than 5.
Q9. Print all property names of the object using for...in.
Answer
let student = {
name: "Rahul",
age: 20,
course: "JavaScript"
};
for (let key in student) {
console.log(key);}
Output
name
age
course
Explanation
for...in loops through the keys (property names) of an object.
It prints name, age, and course.
Q10. Print every fruit using for...of.
Answer
let fruits = ["Apple", "Banana", "Mango", "Orange"];
for (let fruit of fruits) {
console.log(fruit);}
Output
Apple
Banana
Mango
Orange
Explanation
for...of loops through the values of an array.
It prints each fruit one by one.
--------------------------------------------------------------------------
Quick Answer Summary :
Question Topic Key Concept
Q1 for Loop Print numbers 1β20
Q2 for + if Print even numbers
Q3 for + if Print odd numbers
Q4 if...else if...else Positive, Negative, Zero
Q5 if...else Even or Odd
Q6 switch Month Name
Q7 while Loop Print 10 to 1
Q8 do...while Loop Print 1 to 5
Q9 for...in Print object keys
Q10 for...of Print array values
This answer key is ideal for beginners, with straightforward solutions that use only the concepts covered in this lessons and brief
π Node.js Test β Part 1
https://www.youtube.com/watch?v=j6N-On2ZUZ0
Answer Key :
Q1. Display Even Numbers Between 1 and 50
Answer
}
Short Explanation :
The for loop runs from 1 to 50.
% (modulus) gives the remainder.
If the remainder is 0, the number is even and gets printed.
Q2. Find the Largest Number
Answer
}
Output
Short Explanation
Compare num1 and num2.
If num1 is greater, print num1.
Otherwise, print num2.
Q3. Reverse Counting
Answer
}
Short Explanation
Start with 20.
Continue the loop while i >= 1.
Decrease the value by 1 after every iteration.
Q4. Multiplication Table of 7
Answer
}
Output
Short Explanation
The loop runs from 1 to 10.
In each iteration, multiply 7 by the current value of i.
Print the result in table format.
Q5. Count Positive and Negative Numbers
Answer
Output
Short Explanation
Create two counters: positive and negative.
Traverse the array using for...of.
Increase the appropriate counter based on whether the number is greater than or less than 0.
Print the final counts.
π Quick Answer Summary
Q. No. Topic Key Concept
Q1 Even Numbers for loop + % operator
Q2 Largest Number if...else
Q3 Reverse Counting while loop
Q4 Multiplication Table for loop + arithmetic operators
Q5 Count Positive & Negative for...of loop + counters + if...else if
β Difficulty Level
Q1: β Beginner+
Q2: β Beginner+
Q3: ββ Medium
Q4: ββ Medium
Q5: βββ Medium
This answer key uses only the concepts covered so far (variables, loops, conditional statements, arrays, and console output), making it ideal for evaluating students after the Node.js Introduction β Part 1 session.
https://www.youtube.com/watch?v=j6N-On2ZUZ0
Answer Key :
Q1. Display Even Numbers Between 1 and 50
Answer
// Q1. Print Even Numbers from 1 to 50
for (let i = 1; i <= 50; i++) {
if (i % 2 === 0) {
console.log(i);
}}
Short Explanation :
The for loop runs from 1 to 50.
% (modulus) gives the remainder.
If the remainder is 0, the number is even and gets printed.
Q2. Find the Largest Number
Answer
// Q2. Find the Largest Number
let num1 = 45;
let num2 = 78;
if (num1 > num2) {
console.log(num1 + " is the largest number.");
} else {
console.log(num2 + " is the largest number.");}
Output
78 is the largest number.
Short Explanation
Compare num1 and num2.
If num1 is greater, print num1.
Otherwise, print num2.
Q3. Reverse Counting
Answer
// Q3. Print Numbers from 20 to 1
let i = 20;
while (i >= 1) {
console.log(i);
i--;}
Short Explanation
Start with 20.
Continue the loop while i >= 1.
Decrease the value by 1 after every iteration.
Q4. Multiplication Table of 7
Answer
// Q4. Multiplication Table of 7
let number = 7;
for (let i = 1; i <= 10; i++) {
console.log(number + " x " + i + " = " + (number * i));}
Output
7 x 1 = 7
7 x 2 = 14
7 x 3 = 21
7 x 4 = 28
7 x 5 = 35
7 x 6 = 42
7 x 7 = 49
7 x 8 = 56
7 x 9 = 63
7 x 10 = 70Short Explanation
The loop runs from 1 to 10.
In each iteration, multiply 7 by the current value of i.
Print the result in table format.
Q5. Count Positive and Negative Numbers
Answer
// Q5. Count Positive and Negative Numbers
let numbers = [10, -5, 8, -2, 15, -9, 20];
let positive = 0;
let negative = 0;
for (let number of numbers) {
if (number > 0) {
positive++;
} else if (number < 0) {
negative++;
}
}
console.log("Positive Numbers: " + positive);
console.log("Negative Numbers: " + negative);Output
Positive Numbers: 4
Negative Numbers: 3Short Explanation
Create two counters: positive and negative.
Traverse the array using for...of.
Increase the appropriate counter based on whether the number is greater than or less than 0.
Print the final counts.
π Quick Answer Summary
Q. No. Topic Key Concept
Q1 Even Numbers for loop + % operator
Q2 Largest Number if...else
Q3 Reverse Counting while loop
Q4 Multiplication Table for loop + arithmetic operators
Q5 Count Positive & Negative for...of loop + counters + if...else if
β Difficulty Level
Q1: β Beginner+
Q2: β Beginner+
Q3: ββ Medium
Q4: ββ Medium
Q5: βββ Medium
This answer key uses only the concepts covered so far (variables, loops, conditional statements, arrays, and console output), making it ideal for evaluating students after the Node.js Introduction β Part 1 session.
YouTube
Node.js Tutorial for Beginner: Install, Setup & Logic Practice | Part1 #node #nodejs #nodejstutorial
Welcome to the First Official Node.js Video of our Complete Backend Development Course! π
Our JavaScript Quick Revision is complete, and it is time to dive into the core backend environment! In this video, we officially start our Node.js journey. If youβ¦
Our JavaScript Quick Revision is complete, and it is time to dive into the core backend environment! In this video, we officially start our Node.js journey. If youβ¦
π Node.js Practice Tasks β Answer Key
video part 2 β
https://www.youtube.com/watch?v=aMmkF2lLGuw
β Task 1
Create a custom module math.js with multiply() and divide() functions. Require it in another file and print the results.
File 1: math.js
Short Explanation
We created two functions: multiply() and divide().
module.exports is used to export these functions.
Other files can now use these functions by importing this module.
File 2: index.js
Output
Short Explanation
require("./math") imports the math.js module.
We call the exported functions using math.multiply() and math.divide().
The results are displayed using console.log().
---------------------------------------Task 2------------------------------------------------
β Task 2
Create a module info.js that exports your name, role, and institute.
File 1: info.js
Short Explanation
We created an object named info.
The object contains three properties:
name
role
institute
The entire object is exported using module.exports.
File 2: index.js
Output
Short Explanation
require("./info") imports the object from info.js.
We access each property using dot notation (info.name, info.role, info.institute).
The values are printed to the console.
π Concepts Covered
β Creating custom modules
β Exporting functions using module.exports
β Exporting objects
β Importing modules using require()
β Accessing exported functions and object properties
β Printing output with console.log()
Note: Both tasks use CommonJS modules, which is the default module system in Node.js. Students should place both files in the same folder so that require("./math") and require("./info") work correctly.
video part 2 β
https://www.youtube.com/watch?v=aMmkF2lLGuw
β Task 1
Create a custom module math.js with multiply() and divide() functions. Require it in another file and print the results.
File 1: math.js
// math.js
function multiply(a, b) {
return a * b;
}
function divide(a, b) {
return a / b;
}
module.exports = {
multiply,
divide
};Short Explanation
We created two functions: multiply() and divide().
module.exports is used to export these functions.
Other files can now use these functions by importing this module.
File 2: index.js
// index.js
const math = require("./math");
console.log("Multiplication:", math.multiply(10, 5));
console.log("Division:", math.divide(20, 4));Output
Multiplication: 50
Division: 5
Short Explanation
require("./math") imports the math.js module.
We call the exported functions using math.multiply() and math.divide().
The results are displayed using console.log().
---------------------------------------Task 2------------------------------------------------
β Task 2
Create a module info.js that exports your name, role, and institute.
File 1: info.js
// info.js
const info = {
name: "Payal Porwal",
role: "Software Engineer",
institute: "Knowledge Factory 22"
};
module.exports = info;Short Explanation
We created an object named info.
The object contains three properties:
name
role
institute
The entire object is exported using module.exports.
File 2: index.js
// index.js
const info = require("./info");
console.log("Name:", info.name);
console.log("Role:", info.role);
console.log("Institute:", info.institute);Output
Name: Payal Porwal
Role: Software Engineer
Institute: Knowledge Factory 22
Short Explanation
require("./info") imports the object from info.js.
We access each property using dot notation (info.name, info.role, info.institute).
The values are printed to the console.
π Concepts Covered
β Creating custom modules
β Exporting functions using module.exports
β Exporting objects
β Importing modules using require()
β Accessing exported functions and object properties
β Printing output with console.log()
Note: Both tasks use CommonJS modules, which is the default module system in Node.js. Students should place both files in the same folder so that require("./math") and require("./info") work correctly.
YouTube
Node.js Modules Mastery: require() & module.exports In-Depth | Part 2 #node #nodejs #nodejstutorial
Welcome to Part 2 of the Complete Node.js Backend Course! π
To build scalable and production-ready applications, you must understand how to organize your code. In this practical tutorial, we dive deep into Node.js Modules! We will break down exactly howβ¦
To build scalable and production-ready applications, you must understand how to organize your code. In this practical tutorial, we dive deep into Node.js Modules! We will break down exactly howβ¦