Knowledge factory 22
183 subscribers
7 photos
6 files
88 links
πŸš€ Knowledge Factory 22 – Learn Web Dev, App Dev & PWAs with real projects, coding tips, interview prep & industry insights. πŸ“š Stay updated with articles, notes & code!
Download Telegram
This Week in AI - Major Global Developments πŸš€πŸ§ πŸ“ˆ

Foundation Models & Big AI Platfor
ms
* Anthropic’s Claude reportedly crossed 11 million daily active users, narrowing the usage gap with OpenAI’s ChatGPT and signaling stronger enterprise + developer adoption.
* OpenAI is reported to have launched GPT-5.4 Mini and Nano, pushing smaller high-efficiency models for lower-cost deployment and edge inference.
* Mistral AI announced Mistral Forge, a new platform aimed at enterprise model deployment and customization.
* MiniMax introduced M2.7, a model designed to self-improve and reportedly reduce 30–50% of reinforcement learning workflow overhead.
* Meta Platforms delayed launch of its upcoming model Avocado due to internal performance concerns.
* Midjourney released an early version of V8, signaling another jump in image realism and prompt adherence.

NVIDIA Dominates the Week
* NVIDIA introduced NeMo + Claw Stack, strengthening its AI infrastructure ecosystem for agent development and enterprise deployment.
* At NVIDIA GTC, NVIDIA made multiple major announcements:
* 1) DLSS 5
* 2) Vera Rubin, a next-generation seven-chip AI platform
* 3) Long-term concept of space-based data center infrastructure
* 4) NVIDIA also continues expanding beyond chips into full-stack AI platforms, reinforcing its dominance in compute infrastructure.

Apple, China & Hardware Signals
* Apple Inc.’s Mac mini reportedly saw major stock pressure in China, partly linked to demand from local AI developers experimenting with open model stacks.
* China issued a second warning regarding risks associated with OpenClaw-style open agent systems, showing growing regulatory concern over autonomous AI tools.
* Apple also acquired MotionVFX, indicating stronger movement toward AI-assisted video creation workflows.

AI Agents: Rapid Acceleration
* A security incident showed an AI agent breaching a major consulting firm's internal AI environment in roughly two hours, raising fresh questions on enterprise agent security.
* Developers demonstrated a full AI office agent environment built using OpenClaw, showing autonomous task execution across office workflows.
* OpenAI launched Parameter Golf, a concept focused on maximizing output quality with smaller model parameter efficiency.
* Reports suggest ChatGPT may eventually adopt usage-based pricing tiers depending on intensity and type of usage.

AI Video War Intensifies
* Runway demonstrated real-time video generation, a major leap toward live AI media creation.
* ByteDance paused global rollout of Seedance 2.0, possibly due to strategic recalibration.

Research, Science & Emerging Tech
* Scientists announced what is being described as the world’s first quantum battery breakthrough, potentially significant for future energy systems.
* Researchers found that half of AI-generated code passing industrial benchmarks would still be rejected by human developers, highlighting reliability gaps.
* A new study suggests AI chatbots may worsen mental health issues in vulnerable users if not carefully deployed.
* AI companies are reportedly hiring actors to improve emotional realism in model responses.
* Indian researchers developed a system that converts inaudible murmurs into understandable speech, which could transform accessibility technology.

Strategic Industry Moves
* Anthropic launched the Anthropic Institute, likely aimed at long-term AI governance and safety research.
* OpenAI and Anthropic reportedly began hiring chemical and weapons domain experts, indicating deeper work on safety evaluation.
* xAI hired senior leadership from Cursor’s ecosystem.
* Meta Platforms announced four MTIA chip generations planned within two years, signaling aggressive AI silicon ambitions.

* Indian Space Research Organisation’s NavIC reportedly experienced service disruption, raising strategic navigation concerns.
* India continues to produce strong applied AI innovation, especially in speech and embedded AI systems.
Today, let's understand another programming concept:

πŸ”₯ Data Structur
es

This is one of the most important topics for coding interviews.

πŸ“¦ What is a Data Structure?

A Data Structure is a way of organizing and storing data efficiently so it can be:
β€’ accessed quickly
β€’ modified easily
β€’ processed effectively

πŸ‘‰ Choosing the right data structure can optimize performance significantly.

🧠 Types of Data Structures

1️⃣ Linear Data Structures

Elements are arranged sequentially
β€’ Array
– Fixed size
– Fast access using index
– Example use: storing marks
β€’ Linked List
– Elements connected via pointers
– Dynamic size
– Slower access, faster insertion
β€’ Stack (LIFO)
– Last In First Out
– Operations: push, pop
– πŸ‘‰ Example: Undo feature
β€’ Queue (FIFO)
– First In First Out
– πŸ‘‰ Example: Ticket system

2️⃣ Non-Linear Data Structures

Elements are arranged hierarchically
β€’ 🌳 Tree
– Parent-child structure
– Used in databases, file systems
β€’ 🌐 Graph
– Nodes connected via edges
– Used in networks, maps

⚑ Key Operations

E
very data structure supports:
β€’ Insertion
β€’ Deletion
β€’ Traversal
β€’ Searching
β€’ Sorting

🎯 When to Use What

P
roblem Type β†’ Data Structure
β€’ Fast lookup β†’ HashMap
β€’ Ordered data β†’ Array / List
β€’ Undo operations β†’ Stack
β€’ Scheduling β†’ Queue
β€’ Hierarchical data β†’ Tree
β€’ Network problems β†’ Graph

⚠️ Common Interview Mistakes
β€’
❌ Using wrong data structure
β€’ ❌ Ignoring time complexity
β€’ ❌ Not considering edge cases
β€’ ❌ Overcomplicating solution

⭐ Real-World Usage
Da
ta structures are used in:
β€’ Databases
β€’ Search engines
β€’ Social networks
β€’ Navigation systems
β€’ Machine learning

🧠 Important Interview Questions
β€’
Difference between Array Linked List
β€’ Stack vs Queue
β€’ What is HashMap?
β€’ Tree traversal types
β€’ BFS vs DFS

Double Tap ❀️ For More
Today, let's understand another programming concept:

πŸ”₯ Sorting AlgorithmsπŸ“Š
πŸ’»

Sorting is one of the most frequently asked topics in coding interviews.

πŸ“Œ What is Sorting?

Sorting means arranging data in a specific order:

- Ascending β†’ 1, 2, 3, 4
- Descending β†’ 4, 3, 2, 1

Used in:
- Searching
- Data analysis
- Databases
- Optimization problems

🧠 Important Sorting Algorithms

1️⃣ Bubble Sort
- Concept: Repeatedly compares adjacent elements and swaps them if they are in the wrong order.
- Example: [5, 3, 2] β†’ compare 5 & 3 β†’ swap β†’ [3, 5, 2]
- Key Point: Simple but inefficient
- Time Complexity: O(nΒ²)

2️⃣ Selection Sort
- Concept: Find the smallest element and place it at the beginning.
- Example: [4, 2, 1] β†’ pick 1 β†’ place at start β†’ [1, 2, 4]
- Key Point: Fewer swaps than bubble sort
- Time Complexity: O(nΒ²)

3️⃣ Insertion Sort
- Concept: Builds sorted list one element at a time.
- Example: [3, 1, 2] Insert 1 in correct position β†’ [1, 3, 2]
- Key Point: Efficient for small datasets
- Time Complexity: O(nΒ²), but good for nearly sorted data

4️⃣ Merge Sort
- Concept: Divide array into halves, sort them, then merge.
- Example: [4,2,1,3] β†’ split β†’ [4,2] & [1,3] β†’ sort β†’ merge
- Key Point: Very efficient
- Time Complexity: O(n log n)
- Uses extra memory

5️⃣ Quick Sort
- Concept: Pick a pivot and place smaller elements on left, larger on right.
- Example: [4,2,5,1] β†’ pivot = 4 β†’ [2,1] 4 [5]
- Key Point: Very fast in practice
- Average: O(n log n)
- Worst: O(nΒ²)

🎯 When to Use What
-
Small dataset β†’ Insertion Sort
- Large dataset β†’ Merge / Quick Sort
- Nearly sorted β†’ Insertion Sort
- Memory constraint β†’ Quick Sort

⚠️ Common Interview Questions
- Which sorting is fastest? πŸ‘‰ Quick Sort (average case)
- Which is stable? πŸ‘‰ Merge Sort
- Which uses divide & conquer? πŸ‘‰ Merge & Quick Sort

⭐ Real Insight
In
terviewers test:
- Understanding of logic
- Time complexity
- When to use which algorithm

Double Tap ❀️ For More
βœ… Useful Platform to Practice SQL Programming 🧠πŸ–₯️

Learning SQL is just the first step β€” practice is what builds real skill. Here are the best platforms for hands-on SQL:

1️⃣ LeetCode – For Interview-Oriented SQL Practice
β€’ Focus: Real interview-style problems
β€’ Levels: Easy to Hard
β€’ Schema + Sample Data Provided
β€’ Great for: Data Analyst, Data Engineer, FAANG roles
βœ” Tip: Start with Easy β†’ filter by β€œDatabase” tag
βœ” Popular Section: Database β†’ Top 50 SQL Questions
Example Problem: β€œFind duplicate emails in a user table” β†’ Practice filtering, GROUP BY, HAVING

2️⃣ HackerRank – Structured & Beginner-Friendly
β€’ Focus: Step-by-step SQL track
β€’ Has certification tests (SQL Basic, Intermediate)
β€’ Problem sets by topic: SELECT, JOINs, Aggregations, etc.
βœ” Tip: Follow the full SQL track
βœ” Bonus: Company-specific challenges
Try: β€œRevising Aggregations – The Count Function” β†’ Build confidence with small wins

3️⃣ Mode Analytics – Real-World SQL in Business Context
β€’ Focus: Business intelligence + SQL
β€’ Uses real-world datasets (e.g., e-commerce, finance)
β€’ Has an in-browser SQL editor with live data
βœ” Best for: Practicing dashboard-level queries
βœ” Tip: Try the SQL case studies & tutorials

4️⃣ StrataScratch – Interview Questions from Real Companies
β€’ 500+ problems from companies like Uber, Netflix, Google
β€’ Split by company, difficulty, and topic
βœ” Best for: Intermediate to advanced level
βœ” Tip: Try β€œHard” questions after doing 30–50 easy/medium

5️⃣ DataLemur – Short, Practical SQL Problems
β€’ Crisp and to the point
β€’ Good UI, fast learning
β€’ Real interview-style logic
βœ” Use when: You want fast, smart SQL drills

πŸ“Œ How to Practice Effectively:
β€’ Spend 20–30 mins/day
β€’ Focus on JOINs, GROUP BY, HAVING, Subqueries
β€’ Analyze problem β†’ write β†’ debug β†’ re-write
β€’ After solving, explain your logic out loud

πŸ§ͺ Practice Task:
Try solving 5 SQL questions from LeetCode or HackerRank this week. Start with SELECT, WHERE, and GROUP BY.

πŸ’¬ Tap ❀️ for more!
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
JavaScript Interview Practice Questions (Logic Building Test)
Section A – If-Else & Basic Logi
c
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.

Q
8.

Print all odd numbers between 1 and 100.

Q
9.

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.

Q
12.

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.

Di
splay 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.

Us
e the reduce() method to calculate the sum of all array elements.

Q34.

Ch
eck whether a particular value exists in an array using array methods.

Q35.

Co
nvert an array into a comma-separated string.

Section F – Strings
Q
36.

Co
unt the number of vowels in a string.

Q37.

Co
unt the frequency of each character in a string.

Q38.

Fi
nd the longest word in a sentence.

Q39.

Ch
eck whether two strings are Anagrams.

Q40.

Reverse every word in a sentence.

Section G – Objects
Q41.

Pri
nt all keys and values of an object using for...in.

Q42.

Co
unt 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.
Write a program to display the following pattern:

*
****
***
**
*


Q52.
Write a program to display the following pattern:

*
***
*
***
*********


Q53.
Write a program to
display the following pattern:

1
12
123
1234
12345


Q54.
Write 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 : Rahul
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:
12 22

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:
42

Explanation: x++ returns 20, then x becomes 21. ++x makes it 22. Result = 20 + 22 = 42.


Q3
Output:
103

Explanation: 10 + "5" becomes "105" (string concatenation), then "105" - 2 = 103.


Q4
Output:
object

Explanation: typeof null returns "object" due to a historical JavaScript bug.


Q5
Output:
object

Explanation: Arrays are special types of objects, so typeof [] returns "object".


Q6
Output:
JAVASCRIPT

Explanation: trim() removes spaces and toUpperCase() converts all characters to uppercase.


Q7
Output:
Knowledge

Explanation: slice(0,9) returns characters from index 0 to 8.


Q8
Output:
Script

Explanation: substring(4,10) returns characters from index 4 to 9.


Q9
Output:
HelloHello

Explanation: 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:
true

Explanation: includes(20) checks whether 20 exists in the array.


Q15
Output:
true

Explanation: Every element is even, so every() returns true.


Q16
Output:
true

Explanation: 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:
10

Explanation: Object.freeze() prevents modification of existing properties, so a remains 10.


Q20
Output:
No

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
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:
5 == "5" // true
5 === "5" // fals
e

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:

let a = 5;
console.log(++a); // 6

let b = 5;
console.log(b++); // 5
console.log(b); //
6

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:

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:

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:

let arr = [10,20,30];

arr.indexOf(20); // 1
arr.includes(20); // tru
e

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:

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; // tru
e

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.