
- Main
- Catalog
- Computer science
- Web Development - Javascript Courses
Web Development - Javascript Courses
Get free resources to learn web development , html , CSS , JavaScript , reactjs , wordpress , Php , nodejs, etc.
Channel statistics
for (let i = 1; i <= 5; i++) {
if (i === 3) {
break;
}
console.log(i);
}
{}
Using return Inside Functions
function test() {
for (let i = 1; i <= 5; i++) {
if (i === 3) {
return;
}
console.log(i);
}
}
test();
{}
Important:
forEach() does not support break directly.
Use:
• for
• for...of
• some()
• every()
for early exits.
Double Tap ❤️ For Part-5
let age = 18;
if (age >= 18) {
console.log("Adult");
} else {
console.log("Minor");
}
{}
switch
Used when checking multiple possible values.
let day = 2;
switch(day) {
case 1:
console.log("Monday");
break;
case 2:
console.log("Tuesday");
break;
default:
console.log("Invalid Day");
}
{}
Difference:
if/else - Better for conditions/ranges, Flexible
switch - Better for exact values, Cleaner for many cases
32. What is the difference between for, for...in, and for...of?
for
Traditional loop.
for (let i = 0; i < 3; i++) {
console.log(i);
}
{}
for...in
Used for iterating object keys.
const person = {
name: "Deepak",
age: 25
};
for (let key in person) {
console.log(key);
}
{}
for...of
Used for iterable values like arrays.
const nums = [1, 2, 3];
for (let num of nums) {
console.log(num);
}
{}
Key Difference:
Loop - Best For
for - Full control
for...in - Object properties
for...of - Array values
33. What is the while and do-while loop?
Both loops execute code repeatedly while a condition is true.
while Loop
Condition checked before execution.
let i = 1;
while (i <= 3) {
console.log(i);
i++;
}
{}
do-while Loop
Runs at least once before checking condition.
let i = 1;
do {
console.log(i);
i++;
} while(i <= 3);
{}
Difference:
while - Condition first, May run zero times
do-while - Code first, Runs at least once
34. What is the ternary operator?
The ternary operator is a shorthand for if/else.
Syntax:
condition? trueValue : falseValue
Example:
let age = 20;
let result = age >= 18 ? "Adult" : "Minor";
console.log(result);
{}
Benefits:
• Shorter code
• Cleaner simple conditions
35. What is short-circuit evaluation?
JavaScript stops evaluating expressions as soon as the result is known.
Using &&
Returns first falsy value.
console.log(false && "Hello");
{}
Output:
false
Using ||
Returns first truthy value.
console.log("" || "Default");
{}
Output:
Default
Practical Example:
let username = "";
let displayName = username || "Guest";
console.log(displayName);
{}
36. What is the difference between break and continue?
Keyword - Purpose
break - Stops the loop completely
continue - Skips current iteration
break Example
for (let i = 1; i <= 5; i++) {
if (i === 3) {
break;
}
console.log(i);
}
{}
Output:
1
2
continue Example
for (let i = 1; i <= 5; i++) {
if (i === 3) {
continue;
}
console.log(i);
}
{}
Output:
1
2
4
5
37. How do you iterate over an array or object?
Array Iteration
Using forEach()
const nums = [1, 2, 3];
nums.forEach(num => {
console.log(num);
});
{}
Object Iteration
Using for...in
const person = {
name: "Deepak",
age: 25
};
for (let key in person) {
console.log(key, person[key]);
}
{}
Using Object.keys()
Object.keys(person).forEach(key => {
console.log(key);
});
{}
38. How do you implement recursion?
Recursion is when a function calls itself until a stopping condition is met.
Example: Factorial
function factorial(n) {
if (n === 1) {
return 1;
}
return n * factorial(n - 1);
}
console.log(factorial(5));
{}
Output:
120
Important Parts:
1. Base condition
2. Recursive call
Without a base condition → infinite recursion.
39. When would you use for vs forEach()?
for Loop vs forEach()
for - More control, Can use break/continue, Faster in heavy loops
forEach() - Cleaner syntax, Cannot stop early, Better readability
for Example
for (let i = 0; i < 3; i++) {
console.log(i);
}
{}
forEach() Example
[1, 2, 3].forEach(num => {
console.log(num);
});
{}
Interview Tip:
Use forEach() for readability and for when more control is needed.
40. How do you handle early exits from loops?
Using break
function sum(...numbers) {
return numbers.reduce((total, num) => total + num, 0);
}
console.log(sum(1, 2, 3, 4));
{}
Output: 10
Benefits:
- Accept unlimited arguments
- Cleaner function handling
Difference Between Spread and Rest:
Rest (...) → Collect values
Spread (...) → Expand values
Spread Example:
const nums = [1, 2, 3];
console.log(...nums);
{}
Double Tap ❤️ For Part-3
function greet() {
console.log("Hello");
}
{}
Calling a Function: greet();
Function With Parameters:
function greet(name) {
console.log("Hello " + name);
}
greet("Deepak");
{}
12. What is a function declaration vs expression?
Function Declaration
Defined using the function keyword with a name.
function add(a, b) {
return a + b;
}
{}
Function Expression
Function stored inside a variable.
const add = function(a, b) {
return a + b;
};
{}
Feature Comparison:
Hoisted → Declaration: Yes, Expression: No
Named → Declaration: Usually, Expression: Can be anonymous
Key Point:
Function declarations can be called before they are defined because of hoisting.
13. What is an arrow function?
Arrow functions are a shorter syntax for writing functions introduced in ES6.
Syntax:
const greet = () => {
console.log("Hello");
};
{}
Example With Parameters:
const add = (a, b) => a + b;
console.log(add(2, 3));
{}
Benefits:
• Shorter syntax
• Cleaner code
• No own this binding
Important:
Arrow functions should not be used as object methods when this is required.
14. What is hoisting?
Hoisting is JavaScript’s behavior of moving declarations to the top of the scope before execution.
Example:
console.log(a);
var a = 10;
{}
Internally:
var a;
console.log(a);
a = 10;
{}
Output: undefined
Important Points:
• var is hoisted and initialized as undefined
• let and const are hoisted but stay in the Temporal Dead Zone (TDZ)
Function Hoisting:
sayHello();
function sayHello() {
console.log("Hello");
}
{}
15. What is a closure?
A closure is created when an inner function remembers variables from its outer function even after the outer function has finished execution.
Example:
function outer() {
let count = 0;
return function inner() {
count++;
console.log(count);
};
}
const counter = outer();
counter(); // 1
counter(); // 2
{}
Why Closures Are Useful:
• Data privacy
• Maintaining state
• Callbacks
• Memoization
Interview Definition:
A closure gives a function access to its outer scope even after the outer function is executed.
16. What is the module pattern?
The module pattern is used to create private and public variables/functions using closures.
Example:
const Counter = (function() {
let count = 0;
return {
increment: function() {
count++;
console.log(count);
},
decrement: function() {
count--;
console.log(count);
}
};
})();
{}
Counter.increment();
Counter.increment();
Benefits:
• Encapsulation
• Data hiding
• Avoids global scope pollution
17. What is IIFE?
IIFE stands for:
Immediately Invoked Function Expression
It runs immediately after being created.
Syntax:
(function() {
console.log("IIFE Executed");
})();
{}
Arrow Function IIFE:
(() => {
console.log("Hello");
})();
{}
Why Use IIFE?
• Avoid global variables
• Create private scope
• Execute code instantly
18. What is the difference between function parameters and arguments?
Parameters → Variables in function definition
Arguments → Actual values passed to function
Example:
function greet(name) { // Parameter
console.log(name);
}
greet("Deepak"); // Argument
{}
Key Point:
• Parameters receive values
• Arguments send values
19. What is a default parameter?
Default parameters allow functions to use a default value if no argument is passed.
Example:
function greet(name = "Guest") {
console.log("Hello " + name);
}
greet();
greet("Deepak");
{}
Output:
Hello Guest
Hello Deepak
Benefit:
Prevents undefined values.
20. How do optional / rest parameters (...args) work?
Rest parameters collect multiple arguments into a single array.Reviews channel
5 total reviews
- Added: Newest first
- Added: Oldest first
- Rating: High to low
- Rating: Low to high
Catalog of Telegram Channels for Native Placements
Web Development - Javascript Courses is a Telegram channel in the category «Интернет технологии», offering effective formats for placing advertising posts on TG. The channel has 54.5K subscribers and provides quality content. The advertising posts on the channel help brands attract audience attention and increase reach. The channel's rating is 13.1, with 5 reviews and an average score of 5.0.
You can launch an advertising campaign through the Telega.in service, choosing a convenient format for placement. The Platform provides transparent cooperation conditions and offers detailed analytics. The placement cost is 25.2 ₽, and with 15 completed requests, the channel has established itself as a reliable partner for advertising on Telegram. Place integrations today and attract new clients!
You will be able to add channels from the catalog to the cart again.
Комментарий