Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit b45f338

Browse files
committedApr 4, 2023
add new notes
1 parent a5f713d commit b45f338

35 files changed

+873
-1239
lines changed
 

‎notes/Hindi/13-string.md

Lines changed: 0 additions & 238 deletions
This file was deleted.
File renamed without changes.

‎notes/Hindi/15-loopand_switch.md

Lines changed: 0 additions & 342 deletions
This file was deleted.
File renamed without changes.

‎notes/Hindi/17-loopand_switch.md

Lines changed: 352 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,352 @@
1+
### What is loop
2+
3+
Loop ek programming construct hai jo ek block of code ko baar-baar execute karne ki permission deta hai. Ye ek aisa mechanism hai jiska use hum repetitive tasks ko asaani se solve karne ke liye karte hai.
4+
5+
Javascript mein 3 types ke loops hote hai: for loop, while loop, aur do-while loop.
6+
7+
For loop ka use jab karna hota hai jab humein ek list ya array ko iterate karna hota hai. For loop ke andar hum ek counter variable ka use karte hai jo humein bata hai ki loop kitni baar repeat hona hai. Yeh loop syntax ke andar 3 expressions hoti hai: initialization, condition, and update.
8+
9+
Example:
10+
11+
```
12+
for (var i = 0; i < 5; i++) {
13+
console.log("Hello " + i);
14+
}
15+
```
16+
17+
Iss example mein, hum for loop ka use kar rahe hai jisse "Hello" string 0 se 4 tak print ho raha hai. Loop ke andar, humne ek counter variable "i" initialize kiya hai jiska starting value 0 hai, aur humne yeh bhi decide kiya hai ki yeh loop tab tak chalega jab tak "i" ki value 5 se kam hai, iske baad humne "i" ko increment kiya hai.
18+
19+
While loop ka use jab karna hota hai jab humein kisi task ko perform karte waqt ek condition ko check karna hota hai. While loop ke andar hum sirf ek condition statement dete hai jisse hum yeh decide karte hai ki loop continue hoga ya nahi.
20+
21+
Example:
22+
23+
```
24+
var num = 0;
25+
while (num < 5) {
26+
console.log("World " + num);
27+
num++;
28+
}
29+
```
30+
31+
Iss example mein, hum while loop ka use kar rahe hai jisse "World" string 0 se 4 tak print ho raha hai. Humne "num" variable ko initialize kiya hai, aur uski value zero rakhi hai. While loop ke andar, humne yeh decide kiya hai ki jab tak "num" ki value 5 se kam hai, tab tak loop continue kare. Har baar loop execute hone par hum "num" ko increment karte hai.
32+
33+
Do-while loop bhi while loop ki tarah hi hota hai, bas ek chhota sa difference hai ki do-while loop mei pehle code block execute hota hai phir condition check ki jaati hai. Iska matlab hai ki do-while loop ke andar ke code block atleast ek baar to execute hoga.
34+
35+
Example:
36+
37+
```
38+
var i = 0;
39+
do {
40+
console.log("Welcome " + i);
41+
i++;
42+
} while (i < 3);
43+
```
44+
45+
Iss example mein, hum do-while loop ka use kar rahe hai jisse "Welcome" string 0 se 2 tak print ho raha hai. Do-while loop ke andar, hum pehle "Welcome" string ko print karte hai, aur phir "i" variable ki value ko increment karte hai. Fir humne condition check ki hai ki kya "i" ki value 3 se kam hai ya nahi. Agar humara answer "true" hai to loop wapas se start hoga aur agar "false" hai to loop stop ho jayega.
46+
47+
Is tarah se loops ka use karke hum repetitive programming tasks ko asaani se solve kar sakte hai.
48+
49+
### What is for loop
50+
51+
For loop JavaScript mein ek tarah ka loop hai jiske dwara hum kisi array ya object ke andar ke har element ko access kar sakte hain. For loop ke ander ek counter variable hoti hai jo ki shuruat se lekar loop ke ant tak badhti rahti hai aur uske dwara hum har ek element ko access kar sakte hain.
52+
53+
For loop ka syntax yeh hai:
54+
55+
```
56+
for (let i = 0; i < array.length; i++) {
57+
// code block to be executed
58+
}
59+
```
60+
61+
Yahan `let i = 0` ek counter variable hai jiska initial value 0 hai, `array.length` array ke length se compare kiya jaata hai aur `i++` loop ke har iteration ke baad counter ko increment karta hai.
62+
63+
Ab ek example lete hain jismein hum ek array ke saare elements ko console par print karenge:
64+
65+
```
66+
const fruits = ["Apple", "Banana", "Orange"];
67+
68+
for (let i = 0; i < fruits.length; i++) {
69+
console.log(fruits[i]);
70+
}
71+
```
72+
73+
Yahan `fruits` ek array hai jismein hum 3 strings store kar rahe hain. For loop ke ander counter variable `i` hai jo 0 se shuruat karta hai aur `fruits.length` (yani 3) tak chalta hai. Har iteration ke baad hum `console.log(fruits[i])` ka use karke current index ki value console par print karte hain.
74+
75+
Iska output niche diya gaya hai:
76+
77+
```
78+
Apple
79+
Banana
80+
Orange
81+
```
82+
83+
### What is for...of loop
84+
85+
"for...of" loop in JavaScript is a way to iterate over iterable objects like Arrays, Strings, Maps, Sets, etc. It is similar to the "for...in" loop, but it provides more concise and readable syntax for looping through elements in an array or other iterable objects.
86+
87+
To use the "for...of" loop, we first declare a variable to hold each element in the iterable object. Then, we use the "of" keyword followed by the iterable object to loop through its elements.
88+
89+
Here's an example of using "for...of" loop to loop through an array of numbers:
90+
91+
```javascript
92+
const numbers = [1, 2, 3, 4];
93+
94+
for (const num of numbers) {
95+
console.log(num); // Output: 1, 2, 3, 4
96+
}
97+
```
98+
99+
In this example, we declared a constant variable "numbers" that holds an array of numbers. We then used "for...of" loop to iterate over each element of the "numbers" array, assigning each element to the variable "num", and logging it to the console.
100+
101+
Another example is to loop through a string:
102+
103+
```javascript
104+
const str = "Hello World";
105+
106+
for (const char of str) {
107+
console.log(char); // Output: H, e, l, l, o, , W, o, r, l, d
108+
}
109+
```
110+
111+
In this example, we declared a constant variable "str" that holds a string value. We then used "for...of" loop to iterate over each character of the string, assigning each character to the variable "char", and logging it to the console.
112+
113+
In summary, "for...of" loop is a convenient way to iterate over the elements of an iterable object in JavaScript.
114+
115+
### What is for...in loop
116+
117+
"for...in" loop is a type of loop in JavaScript that allows you to iterate over the properties of an object. In simple terms, it helps you to loop through each key-value pair of an object and perform some action on them.
118+
119+
Here's an example in Hinglish:
120+
121+
Suppose you have a dictionary (object) with multiple words and their meanings. You want to loop through every word and print its meaning. Here's how you can use "for...in" loop to achieve this:
122+
123+
```
124+
// Define the dictionary object
125+
var dictionary = {
126+
"apple": "seb",
127+
"banana": "kela",
128+
"orange": "santara"
129+
};
130+
131+
// Loop through each word in the dictionary object
132+
for (var word in dictionary) {
133+
134+
// Print the word and its meaning
135+
console.log(word + " ka arth hai " + dictionary[word]);
136+
}
137+
```
138+
139+
In this example, we define an object called "dictionary" with three key-value pairs. We then use a "for...in" loop to loop through each key-value pair in the object. Inside the loop, we print the word and its meaning using the "console.log()" function. The output of this program will be:
140+
141+
```
142+
apple ka arth hai seb
143+
banana ka arth hai kela
144+
orange ka arth hai santara
145+
```
146+
147+
So, the "for...in" loop is a very useful construct in JavaScript for iterating over the properties of an object. It is particularly helpful when you need to work with data stored in objects.
148+
149+
### What is while loop
150+
151+
While loop JavaScript mein ek aisa loop hai jo ek shart ko check karta hai aur jab tak wo shart true rahe, tab tak loop chalta rehta hai.
152+
153+
Is loop ke andar code block ko ek baar bhi nahi chalaya jata hai agar shart hi false hoti hai. While loop ka syntax neeche diya gaya hai:
154+
155+
```
156+
while (shart) {
157+
// Code Block
158+
}
159+
```
160+
161+
Yahan "shart" ek boolean expression hai, jo true ya false ho sakta hai. Aur "Code Block" ek set of statements hai jo execute hote rahtey hai jab tak shart true rahti hai.
162+
163+
Example:
164+
165+
```
166+
let i = 1;
167+
while (i <= 5) {
168+
console.log(i);
169+
i++;
170+
}
171+
```
172+
173+
Iss example mein humne ek variable "i" create kiya aur ek while loop ka use kiya jo "i" ki value 5 se kam hone tak chalta rehta hai. Har baar "i" ki value print hoti hai aur phir "i" ki value 1 se badhaya jaata hai. Jab "i" ki value 6 ho jaati hai to loop khatam ho jaata hai.
174+
175+
Iska output hoga:
176+
177+
```
178+
1
179+
2
180+
3
181+
4
182+
5
183+
```
184+
185+
Ummid hai ki ab aapko while loop ke baare mein achi tarah se samajh aa gaya hoga!
186+
187+
### What is do...while loop
188+
189+
Do...while loop ek aisa loop hai jo kisi bhi code block ko baar-baar execute karta hai jab tak ki uske condition ka result true na ho. Yeh loop pehle code block ko execute karta hai aur phir condition check karta hai. Agar condition true hoti hai to loop continue rahta hai, lekin agar condition false hoti hai tab bhi code block ko kam se kam ek baar execute kar diya jaata hai.
190+
191+
Ek example ke through samajhte hain:
192+
193+
```
194+
var i = 1;
195+
do {
196+
console.log(i);
197+
i++;
198+
} while (i <= 5);
199+
```
200+
201+
Is code mein `i` ki value 1 se start hogi aur do..while loop ke andar code block ko execute karne ke baad `i` ki value 1 se 2 ho jayegi. Phir condition check hoti hai ki kya `i` ki value 5 se choti ya barabar hai? Kyunki yeh condition abhi true hai, isliye loop 2nd iteration ke liye chalta rahega aur `i` ki value 3 ho jayegi. Iss tarah se loop ke har iteration mein `i` ki value badhti rahegi jab tak ki `i` ki value 5 na ho jaye. Jab `i` ki value 6 ho jati hai, to condition false ho jati hai aur loop se bahar nikal jata hai.
202+
203+
Iss tarah se do..while loop ek baar to code block ko execute karta hi hai chahe condition true ho ya false ho.
204+
205+
### What is Switch Statment
206+
207+
Switch statement in JavaScript is a conditional statement that allows you to evaluate an expression and execute different code blocks based on the value of that expression. It's a way to simplify writing multiple if/else statements.
208+
209+
For example, let's say you have a variable called "dayOfWeek" that contains a string representing the day of the week. You want to perform different actions depending on the value of "dayOfWeek". Instead of using multiple if/else statements, you can use a switch statement:
210+
211+
```
212+
var dayOfWeek = "Monday";
213+
214+
switch (dayOfWeek) {
215+
case "Monday":
216+
console.log("It's Monday, time to start the week!");
217+
break;
218+
case "Tuesday":
219+
console.log("It's Tuesday, still a long way to go...");
220+
break;
221+
case "Wednesday":
222+
console.log("It's Wednesday, halfway there!");
223+
break;
224+
case "Thursday":
225+
console.log("It's Thursday, almost done!");
226+
break;
227+
case "Friday":
228+
console.log("It's Friday, yay weekend!");
229+
break;
230+
default:
231+
console.log("Invalid day of the week.");
232+
}
233+
```
234+
235+
In this example, the switch statement evaluates the value of the "dayOfWeek" variable and executes the code block corresponding to the matching case label. If there is no match, the default case is executed.
236+
237+
So, if "dayOfWeek" is "Monday", the output will be "It's Monday, time to start the week!". If "dayOfWeek" is "Saturday", the output will be "Invalid day of the week." because there is no matching case label.
238+
239+
Switch statements are useful when you have a large number of conditions to check and want to avoid writing nested if/else statements.
240+
241+
### What is case clause
242+
243+
"Case clause" (केस क्लॉज) जावास्क्रिप्ट में एक संरचना है जो switch ब्लॉक के अंदर इस्तेमाल की जाती है। यह एक conditional statement है, जो switch block में निर्दिष्ट value को evaluate करती है और शर्तों के आधार पर उपयुक्त code block को execute करती है।
244+
245+
जब switch block की expression की value किसी एक case के value से match करती है, तो उस case के अंदर का code block execute होता है। अगर कोई case match नहीं होता है, तो default case का code block execute होता है।
246+
247+
इसका syntax निम्नलिखित है:
248+
249+
```
250+
switch (expression) {
251+
case value1:
252+
//code block
253+
break;
254+
case value2:
255+
//code block
256+
break;
257+
case value3:
258+
//code block
259+
break;
260+
default:
261+
//code block
262+
}
263+
```
264+
265+
यहाँ expression value को evaluate करने के लिए है जो case के values से match करती हैं। अगर expression किसी bhi case value से match करता है, तो उस case का code block execute होता है। इसके बाद break statement से execution control switch block से बाहर निकल जाता है।
266+
267+
यहाँ एक उदाहरण है:
268+
269+
```
270+
let day = "Monday";
271+
switch (day) {
272+
case "Sunday":
273+
console.log("Today is Sunday");
274+
break;
275+
case "Monday":
276+
console.log("Today is Monday");
277+
break;
278+
case "Tuesday":
279+
console.log("Today is Tuesday");
280+
break;
281+
default:
282+
console.log("Today is some other day");
283+
}
284+
```
285+
286+
इस example में, variable 'day' की value "Monday" है, इसलिए switch block में वह "Monday" case से match होती है। इसलिए उस case के अंदर का code block execute होता है और निम्न output print होता है:
287+
288+
```
289+
Today is Monday
290+
```
291+
292+
### What is break
293+
294+
Break ka matlab hai ek code block se bahar nikalna. Jab tak hum break na use karein, tab tak loop ya switch statement continue hote rahenge.
295+
296+
Ek example ke through samjhate hain:
297+
298+
```
299+
for (let i = 1; i <= 5; i++) {
300+
console.log(i);
301+
if (i === 3) {
302+
break;
303+
}
304+
}
305+
```
306+
307+
Iss code mein, hum for loop ka use karke 1 se 5 tak ke numbers ko print kar rahe hai. Lekin jab `i` ki value 3 ho jaati hai toh humne `break` ka use kiya hai, jisse ki loop uss point pe hi stop ho jaata hai aur aage nahi chalta.
308+
309+
Agar hum issi code ke bina break ka use karte toh output yeh hota:
310+
311+
```
312+
1
313+
2
314+
3
315+
4
316+
5
317+
```
318+
319+
Lekin humne break ka use kiya hai jab `i` ki value 3 ho jaati hai, isliye output yeh hoga:
320+
321+
```
322+
1
323+
2
324+
3
325+
```
326+
327+
Iss tarah, break ka use karke hum loop ya switch statement ko jald se jald exit kar sakte hai.
328+
329+
### What is default case in a Switch Statement ?
330+
331+
Switch Statements are used in programming languages to execute different blocks of code based on the value of an expression.
332+
333+
The default case is a branch in a switch statement that is executed when no other case matches the value of the expression. It is like a catch-all clause in a try-catch block.
334+
335+
For example, let's say we have a variable called "dayOfWeek" which represents the day of the week (1 for Sunday, 2 for Monday, and so on) and we want to print a message depending on the day of the week:
336+
337+
```
338+
int dayOfWeek = 3;
339+
switch(dayOfWeek){
340+
case 1:
341+
System.out.println("Today is Sunday");
342+
break;
343+
case 2:
344+
System.out.println("Today is Monday");
345+
break;
346+
//... cases for other days of the week
347+
default:
348+
System.out.println("Invalid day of the week");
349+
}
350+
```
351+
352+
we could say that the default case is like a "baki sab" option in a switch statement. It is executed when none of the other options match the given value.

‎notes/Hindi/18-string.md

Lines changed: 210 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,210 @@
1+
### What is String
2+
3+
Javascript mein, String ek primitive data type hai jo text ko represent karta hai. Har string ek sequence of characters hoti hai aur ek quotation mark (' ' aur " ") ke beech mein define ki jati hai.
4+
5+
Jaise ki,
6+
7+
```
8+
var naam = 'Amit'; // single quotes mein string ko define kiya gaya hai
9+
var message = "Main aaj khush hoon."; // double quotes mein string ko define kiya gaya hai
10+
```
11+
12+
Ismein, `naam` aur `message` variables string values store kar rahe hai.
13+
14+
String mein characters indexes ke dwara access kiye ja sakte hai. Index 0 se start hota hai aur string.length - 1 tak chalta hai. Iske alawa, hum strings ko concatenate (combine) kar sakte hai `+` operator se.
15+
16+
Jaise ki,
17+
18+
```
19+
var firstName = 'Amit';
20+
var lastName = 'Kumar';
21+
var fullName = firstName + ' ' + lastName; // Concatenate karne ke liye '+'' operator ka use kiya gaya hai.
22+
console.log(fullName); // Output: Amit Kumar
23+
```
24+
25+
Yahan, `fullName` variable `firstName` aur `lastName` strings se combined hai. Hum yeh bhi dekh sakte hai ki space `" "` concatenate karne ke liye bhi use kiya gaya hai.
26+
27+
In summary, String ek primitive data type hai jo text ko represent karta hai. Har string ek sequence of characters hoti hai aur quotation marks ke beech mein define ki jaati hai. Strings ko index ke dwara access kiya ja sakta hai aur concatenate karne ke liye `+` operator ka use kiya jaa sakta hai.
28+
29+
### How to create String
30+
31+
JavaScript mein ek string banane ke liye hum " " ya fir ' ' (single quotes) ka use karte hain. Jaise ki:
32+
33+
```
34+
var str1 = "Hello";
35+
var str2 = 'world';
36+
```
37+
38+
Yahan humne do variables `str1` aur `str2` banaye hain jo ek-ek string hai. `str1` mein "Hello" string hai aur `str2` mein "world".
39+
40+
Agar aapko kuch bhi double quote (" ") ke andar likhna hai jaisa ki `"I'm a string"` toh aap use single quote (' ') ke andar wrap kar sakte hain. Jaise ki:
41+
42+
```
43+
var str3 = 'I\'m a string';
44+
```
45+
46+
Yahan humne `\` ka use kiya hai taaki string mein single quote ka use kar sakein.
47+
48+
Hum multiple strings ko concatenate bhi kar sakte hain, jisse ek naya string banega. Jaise ki:
49+
50+
```
51+
var greeting = str1 + ', ' + str2 + '!'; // Output: Hello, world!
52+
```
53+
54+
Yahan `+` operator ka use kiya gaya hai do strings ko concatenate karne ke liye. `greeting` variable mein ab "Hello, world!" string hai.
55+
56+
Is tarah se hum JavaScript mein strings create kar sakte hain.
57+
58+
### String Literal vs String Object ?
59+
60+
String Literal aur String Object dono tarah ke string hote hai, lekin unke banane ka tarika alag hota hai.
61+
62+
String Literal ek aisa string hai jo code mein directly declare kiya jata hai, aur use double quotes (" ") ya single quotes (' ') ke beech mein likha jata hai. Jab hum isse banate hai to iska ek reference bhi ban jata hai. Jaise:
63+
64+
```
65+
String literal = "Hello World!";
66+
```
67+
68+
String Object ek aisa string hai jo hum new keyword se create karte hai. Ismein humein ek object banaana padta hai jo ki String class ka object hota hai. Jaise:
69+
70+
```
71+
String object = new String("Hello World!");
72+
```
73+
74+
Dono hi tareeke se banaye gaye string mein same value hai, lekin inki memory allocation aur usage mein antar hota hai. Jab hum string literal banate hai to uska reference pool me store ho jaata hai (jise String Constant Pool kehte hai) aur jab hum dusri jagah se usi literal ko use karte hai to woh phele se stored reference ko point karta hai. Lekin jab hum string object banate hai to har baar naya object ban jata hai aur alag-alag memory allocation hoti hai.
75+
76+
Upar diye gaye examples ko hinglish mein likhenge to yeh aise dikhega:
77+
78+
```
79+
// String Literal
80+
String literal = "Hello World!";
81+
82+
//String Object
83+
String object = new String("Hello World!");
84+
```
85+
86+
Ummid hai yeh samjhane mein madad milegi.
87+
88+
### String length property
89+
90+
"String length property" refers to the number of characters in a string. It is a built-in property of the String object in JavaScript and can be accessed using the ".length" syntax.
91+
92+
For example, consider the following code:
93+
94+
```
95+
var name = "ChatGPT";
96+
console.log(name.length); // Output: 7
97+
```
98+
99+
In this code, we have defined a variable "name" with the value "ChatGPT". We then use the ".length" property to find out the length of the string "name", which is 7.
100+
101+
Similarly, we can use the ".length" property to find out the length of any string, as shown below:
102+
103+
```
104+
var message = "Namaste dosto!";
105+
console.log(message.length); // Output: 14
106+
```
107+
108+
Here, we have defined a variable "message" with the value "Namaste dosto!". We then use the ".length" property to find out the length of the string "message", which is 14.
109+
110+
इसका मतलब होता है कि "String length property" एक स्ट्रिंग में उपलब्ध वर्णों की संख्या को दर्शाता है। यह JavaScript में String ऑब्जेक्ट की बिल्ट-इन property होती है और ".length" का syntax उपयोग करके इसे एक्सेस किया जा सकता है।
111+
112+
एक उदाहरण के रूप में, निम्नलिखित कोड का विवरण दिया गया है:
113+
114+
```
115+
var name = "ChatGPT";
116+
console.log(name.length); // Output: 7
117+
```
118+
119+
इस कोड में, हमने एक वेरिएबल "name" को "ChatGPT" के साथ परिभाषित किया है। फिर हम ".length" property का उपयोग करके "name" स्ट्रिंग की लंबाई पता लगाते हैं, जो 7 है।
120+
121+
इसी तरह, हम किसी भी स्ट्रिंग की लंबाई का पता लगाने के लिए ".length" property का उपयोग कर सकते हैं, जैसा कि निम्नलिखित में दिखाया गया है:
122+
123+
```
124+
var message = "Namaste dosto!";
125+
console.log(message.length); // Output: 14
126+
```
127+
128+
यहाँ, हमने "message" वेरिएबल को "Namaste dosto!" के साथ परिभाषित किया है। फिर हम ".length" property का उपयोग करके "message" स्ट्रिंग की लंबाई पता लगाते हैं, जो 14 है।
129+
130+
### String functions
131+
132+
String functions in JavaScript are built-in functions that allow you to manipulate and modify strings. Here's a list of commonly used string functions in JavaScript:
133+
134+
1. length(): This function returns the length of the string.
135+
136+
Example:
137+
var str = "Hello World";
138+
console.log(str.length); // Output: 11
139+
140+
2. toUpperCase(): This function converts all characters in a string to uppercase.
141+
142+
Example:
143+
var str = "hello world";
144+
console.log(str.toUpperCase()); // Output: HELLO WORLD
145+
146+
3. toLowerCase(): This function converts all characters in a string to lowercase.
147+
148+
Example:
149+
var str = "HELLO WORLD";
150+
console.log(str.toLowerCase()); // Output: hello world
151+
152+
4. indexOf(): This function returns the index of the first occurrence of a specified substring in a string.
153+
154+
Example:
155+
var str = "Hello World";
156+
console.log(str.indexOf("o")); // Output: 4
157+
158+
5. slice(): This function extracts a part of a string and returns a new string.
159+
160+
Example:
161+
var str = "Hello World";
162+
console.log(str.slice(0, 5)); // Output: Hello
163+
164+
6. replace(): This function replaces the first occurrence of a specified substring with another substring.
165+
166+
Example:
167+
var str = "Hello World";
168+
console.log(str.replace("Hello", "Hi")); // Output: Hi World
169+
170+
7. trim(): This function removes whitespace from both ends of a string.
171+
172+
Example:
173+
var str = " Hello World ";
174+
console.log(str.trim()); // Output: Hello World
175+
176+
8. concat(): This function joins two or more strings and returns a new string.
177+
178+
Example:
179+
var str1 = "Hello";
180+
var str2 = "World";
181+
console.log(str1.concat(" ", str2)); // Output: Hello World
182+
183+
In Hindi (Devanagari script):
184+
JavaScript में स्ट्रिंग फंक्शंस वह बिल्ट इन फंक्शंस हैं जो आपको स्ट्रिंग को मैनिपुलेट और मॉडिफाई करने की अनुमति देते हैं। यहाँ जावास्क्रिप्ट में उपयोग में आने वाले स्ट्रिंग फंक्शंस की सूची है:
185+
186+
1. length(): यह फंक्शन स्ट्रिंग की लंबाई लौटाता है।
187+
188+
उदाहरण:
189+
var str = "Hello World";
190+
console.log(str.length); // आउटपुट: 11
191+
192+
2. toUpperCase(): यह फंक्शन स्ट्रिंग के सभी अक्षरों को अपरकेस में रूपांतरित करता है।
193+
194+
उदाहरण:
195+
var str = "hello world";
196+
console.log(str.toUpperCase()); // आउटपुट: HELLO WORLD
197+
198+
3. toLowerCase(): यह फंक्शन स्ट्रिंग के सभी अक्षरों को लोअरकेस में रूपांतरित करता है।
199+
200+
उदाहरण:
201+
var str = "HELLO WORLD";
202+
console.log(str.toLowerCase()); // आउटपुट: hello world
203+
204+
4. indexOf(): यह फंक्शन स्ट्रिंग में एक निर्दिष्ट उपस्थिति से पहले उपस्थिती के आधार पर एक सबस्ट्रिंग का इंडेक्स लौटाता है।
205+
206+
उदाहरण:
207+
var str = "Hello World";
208+
console.log(str.indexOf("o")); // आउटपुट: 4
209+
210+
5. slice(): यह फंक

‎notes/Hindi/20-DOM.md

Lines changed: 0 additions & 659 deletions
Large diffs are not rendered by default.
File renamed without changes.
Lines changed: 311 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,311 @@
1+
### What is default parameter ?
2+
3+
Default parameter ek programming concept hai jismein ek function ka argument deafult value se initialize kiya jaata hai. Jaise ki, agar hum kisi function mein ek argument ko default value assign karte hain toh jab bhi uss function ko call kiya jaata hai aur uss argument ka value nahi diya jaata hai, toh woh argument default value ke saath initialize ho jaata hai.
4+
5+
For example, agar hum ek function define karte hain jiska naam hai print_name aur usmein ek argument hai name, toh hum uska default value "Guest" rakh sakte hain. Iska matlab hai ki agar hum print_name function ko call karte hain aur usmein koi Name nahi dete hain toh "Guest" as a default value use ho kar print ho jayega.
6+
7+
Yehi concept Hinglish mein samjhaya jaaye toh - agar tumhein koi party mein invite kiya gaya hai aur invitation mein likha hai ki RSVP pe apna naam dena zaruri hai, lekin agar tumne RSVP mein naam nahi diya toh tum automatically "Guest" ke roop mein count kiye jaoge.
8+
9+
### What is passing arguments: value vs reference in JavaScript ?
10+
11+
JavaScript mein, argument pass karna do tariko se kiya jata hai - value aur reference ke dwara. Value-based argument mein, argument ka copy function ke andar banaya jata hai aur ismein koi bhi changes function se bahar visible nahi hote hain. Jabki reference-based argument mein, original object ya array ko function ke through modify kiya ja sakta hai aur yeh changes function ke bahar bhi visible hote hain.
12+
13+
Value-based argument ka ek example hai:
14+
15+
```
16+
function addOne(num) {
17+
num = num + 1;
18+
console.log(num); // output: 6
19+
}
20+
21+
let myNum = 5;
22+
addOne(myNum);
23+
console.log(myNum); // output: 5
24+
```
25+
26+
Is example mein, `addOne` function ko `myNum` variable ke value ke sath call kiya jata hai, jo ki initially 5 hai. Function mein, `num` variable ko `myNum` ki value se assign kiya jata hai. Iske baad, `num` variable mein 1 add kar diya jata hai. Lekin `myNum` variable ki value function ke bahar waise hi rehti hai jaise pahle thi, yaani 5.
27+
28+
Reference-based argument ka ek example hai:
29+
30+
```
31+
function addToArr(arr, val) {
32+
arr.push(val);
33+
console.log(arr); // output: [1, 2, 3, 4]
34+
}
35+
36+
let myArr = [1, 2, 3];
37+
addToArr(myArr, 4);
38+
console.log(myArr); // output: [1, 2, 3, 4]
39+
```
40+
41+
Is example mein, `addToArr` function ko `myArr` variable ke sath call kiya jata hai, jo `[1, 2, 3]` hai. Function mein, `arr` variable ko `myArr` ki reference se assign kiya jata hai. Iske baad, `val` variable ko 4 se assign kiya jata hai. Fir, `push()` method ka use karke `arr` array mein `val` value add kiya jata hai. Ab, `myArr` variable ki value bhi `addToArr` function ke through modify ho jati hai aur ismein `[1, 2, 3, 4]` ho jata hai.
42+
43+
Is tarah se, value-based argument mein original variable/function ke copy banaya jata hai aur modifications us copy pe kiye jate hain. Jabki reference-based arguments mein original variable ko hi modify kiya jata hai aur changes function ke bahar bhi visible hote hain.
44+
45+
### What is First Class function/Citizen ?
46+
47+
First Class functions (FCF) refer to the ability of a programming language to treat functions as variables or first-class citizens. This means that functions can be assigned to variables, passed as arguments to other functions, and returned as values from functions.
48+
49+
For example, let's consider the following Python code:
50+
51+
```
52+
def add(x, y):
53+
return x + y
54+
55+
result = add(3, 4)
56+
print(result)
57+
```
58+
59+
In this code, `add` is a function that takes two arguments `x` and `y`, and returns their sum. We then assign the value returned by `add(3, 4)` to the variable `result`, which is then printed to the console.
60+
61+
Now, let's see an example of treating a function as a first-class citizen:
62+
63+
```
64+
def add(x, y):
65+
return x + y
66+
67+
def apply(func, x, y):
68+
return func(x, y)
69+
70+
result = apply(add, 3, 4)
71+
print(result)
72+
```
73+
74+
In this code, we have defined a new function `apply` that takes three arguments: a function `func`, and two arguments `x` and `y`. The `apply` function then applies the function `func` to the arguments `x` and `y`.
75+
76+
We then call the `apply` function with the `add` function as the `func` argument, and `3` and `4` as the `x` and `y` arguments. The result of calling `apply` is the same as calling `add(3, 4)`, which is `7`.
77+
78+
So, in summary, first-class functions allow us to treat functions as data, which gives us more flexibility and power when writing code.
79+
80+
### What is High Order function ?
81+
82+
High order function ek aisa function hota hai jo doosre functions ko argument ke roop mein le sakta hai, ya fir ek function ko return kar sakta hai. Iss tarah ke functions ka upyog kisi specific kaam ke liye kaafi flexible aur powerful hota hai.
83+
84+
Ek udaharan ke roop mein, hum ek high order function likh sakte hain jo kisi list ke har item pe apply ho sakta hai aur use double kar sake. Is function ko hum "map" kehte hain:
85+
86+
```python
87+
def double(x):
88+
return x * 2
89+
90+
my_list = [1, 2, 3, 4, 5]
91+
92+
new_list = map(double, my_list)
93+
94+
print(list(new_list)) # Output: [2, 4, 6, 8, 10]
95+
```
96+
97+
Yahaan, `double` function ko `map` function ke argument ke roop mein pass kiya gaya hai. `Map` function ne phir `my_list` ke har item pe `double` function ko apply kiya aur ek naye list mein un values ko store kar diya jismein har value original list ke corresponding value ka double tha.
98+
99+
Iss example mein, `map` function ek high order function hai kyunki usne ek doosre function (`double`) ko apna argument ke roop mein liya hai.
100+
101+
### What is Callback function ?
102+
103+
Callback function ek programming concept hai jisme ek function ko dusre function mein argument ke taur par pass kiya jaata hai aur yeh function baad mein call kiya jaata hai. Yeh kaam karke asynchronous programming mein kaafi help karta hai.
104+
105+
Let's take an example: Suppose humare paas ek function hai jo do numbers ka sum calculate karta hai:
106+
107+
```python
108+
def add_numbers(a, b):
109+
return a + b
110+
```
111+
112+
Ab humein ek aur function banana hai jo kisi bhi do numbers ka product calculate karega, lekin ismein hum chaahte hai ki agar iska calculation complete hua toh humare paas ek message aa jaaye. Iske liye hum callback function ka use karenge:
113+
114+
```python
115+
def multiply_numbers(a, b, callback):
116+
result = a * b
117+
callback(result)
118+
119+
# Ab hum apna callback function bana sakte hain
120+
def print_result(result):
121+
print("Product is:", result)
122+
123+
multiply_numbers(5, 6, print_result)
124+
```
125+
126+
Yahaan humne `multiply_numbers` mein `callback` parameter add kiya jisse hum uss function mein bhejte hain. Fir `multiply_numbers` function mein hum result ko calculate karte hain aur `callback` function ko call kar dete hain jisse wo message print kar sake.
127+
128+
Upar diye gaye example mein humne Python ka use kiya hai, lekin callback functions ka concept kisi bhi programming language mein istemaal kiya ja sakta hai.
129+
130+
### What is setTimeOut ?
131+
132+
setTimeOut ek JavaScript function hai jiske through hum apne code ko delay kar sakte hai. Iske liye, setTimeOut function ko call kiya jata hai aur ismein pehle argument mein ek function define kiya jata hai jo hum delay karna chahte hai, aur dusre argument mein delay time (milliseconds) specify kiya jata hai.
133+
134+
For example:
135+
136+
```
137+
setTimeout(function() {
138+
console.log("Hello, world!");
139+
}, 3000);
140+
```
141+
142+
Is code mein, setTimeout function ko call kiya gaya hai jismein pehla argument ek anonymous function hai jo "Hello, World!" console.log statement print karega, aur dusra argument hai 3000 milliseconds ka delay time hai.
143+
144+
Iss code ko Hinglish mein explain karte hai:
145+
"setTimeout" ek JavaScript function hai jisse hum code mein delay laga sakte hain. Jaise ki agar humein 3 second ke baad "Hello, World!" console mein print karna hai to hum "setTimeout" function use karenge. Ismein hum pehle argument mein "Hello, World!" print karne wali function ko define karenge aur dusre argument mein 3000ms (3 seconds) ka time specify karenge."
146+
147+
### What is setInterval ?
148+
149+
setInterval ek JavaScript function hai jo humein time-based actions ko perform karne mein help karta hai. Iske through, hum ek function ko specific interval ke baad repeatedly call kar sakte hain.
150+
151+
Iske liye sabse pehle hum setInterval() function ko call karte hain aur usmein do parameters pass karte hain:
152+
153+
1. Ek function jo humein har interval ke baad call karna hai.
154+
2. Interval ka duration milliseconds mein kitna hona chahiye.
155+
156+
Jab hum is function ko call karte hain, woh turant ek ID return karta hai jo humare setInterval loop ko stop karne ke liye use kar sakte hain.
157+
158+
Example:
159+
160+
Agar humein 1 second ke interval ke baad "Hello World" print karna hai, to hum is tarah ka code likh sakte hain:
161+
162+
```javascript
163+
let count = 0;
164+
const intervalId = setInterval(() => {
165+
console.log("Hello World");
166+
count++;
167+
if (count === 5) {
168+
clearInterval(intervalId);
169+
}
170+
}, 1000);
171+
```
172+
173+
Iss code mein, humne `count` variable ki madad se 5 iterations ke baad setInterval loop ko stop karne ka condition set kiya hai. Humne `setInterval()` function ko call kiya aur usmein ek anonymous function pass kiya jo 1 second ke interval ke baad "Hello World" print karega.
174+
175+
### what is Function returning a function ?
176+
177+
Function returning a function is when a function returns another function as its output instead of a regular value. The returned function can be stored in a variable and called later.
178+
179+
For example, let's say we want to create a function that adds a given number to any input. We can define this function like this:
180+
181+
```
182+
def add_number(number):
183+
def add_to_input(input_num):
184+
return input_num + number
185+
return add_to_input
186+
```
187+
188+
this would be something like "function jo ek aur function return karta hai". Iska matlab hai ki hum ek aisi function bana sakte hain jismein hum ek number ko diya hai aur ye function ek aur function return karta hai. Ye returned function input number ko liya aur usmein diye hue number ko add karke output dega.
189+
190+
In the above example, `add_number` function takes in a `number` argument and defines an inner function `add_to_input` that takes a single input `input_num`. This inner function adds the `number` passed to it to the `input_num` and returns the result.
191+
192+
The `add_number` function then returns the `add_to_input` function as its output. Now, we can store the returned function in a variable and call it with different inputs like this:
193+
194+
```
195+
add_five = add_number(5)
196+
add_ten = add_number(10)
197+
198+
print(add_five(3)) # Output: 8
199+
print(add_ten(3)) # Output: 13
200+
```
201+
202+
Here, we created two new functions, `add_five` and `add_ten`, by calling the `add_number` function with arguments 5 and 10 respectively. These new functions add 5 and 10 to their inputs, respectively. Calling these new functions with different inputs gives us the desired output.
203+
204+
I hope this helps!
205+
206+
### What are the call and apply methods ?
207+
208+
Call and Apply methods are functions in JavaScript that allow you to invoke a function with a specific context (or "this" value) and arguments.
209+
210+
The difference between the two is that call takes individual arguments separated by commas, while apply takes arguments as an array.
211+
212+
For example, let's say we have a function named "printFullName" which takes two arguments: firstName and lastName. We also have an object named "person" with properties "firstName" and "lastName". We can use the Call method to invoke the "printFullName" function with the "person" object as the context:
213+
214+
```
215+
function printFullName(firstName, lastName) {
216+
console.log(this.firstName + " " + this.lastName);
217+
}
218+
219+
var person = {
220+
firstName: "John",
221+
lastName: "Doe"
222+
}
223+
224+
printFullName.call(person); // Output: John Doe
225+
```
226+
227+
In this example, we used the Call method to invoke the printFullName function with the "person" object as the context. The "this" keyword inside the function now refers to the "person" object, and we get the output "John Doe".
228+
229+
Similarly, to use the Apply method, we can pass the arguments as an array:
230+
231+
```
232+
printFullName.apply(person, ["Jane", "Doe"]); // Output: Jane Doe
233+
```
234+
235+
Here, we passed an array containing two values - "Jane" and "Doe" - as the arguments for the function. The Apply method allows us to pass arguments as an array instead of individual arguments.
236+
237+
So, in summary, Call and Apply methods are used to invoke a function with a specific context (or "this" value) and arguments.
238+
239+
### What is the bind method ?
240+
241+
Bind method ek JavaScript function ka method hai jo humein ek naya function return karta hai. Bind method se hum apne original function ko ek naya "this" value aur arguments ke saath connect kar sakte hai.
242+
243+
Bind method ka syntax aisa hota hai: `function.bind(thisArg, arg1, arg2, ...)`
244+
245+
Ismein `thisArg` ek object hota hai jise hum bind karna chahte hai aur `arg1`, `arg2`, ... baki ke arguments hote hai jo humare original function mein pass kiye jaate hai.
246+
247+
Ek example dekh lete hai:
248+
249+
```
250+
const person = {
251+
firstName: "John",
252+
lastName: "Doe",
253+
fullName: function() {
254+
return this.firstName + " " + this.lastName;
255+
}
256+
}
257+
258+
const printName = person.fullName.bind(person);
259+
260+
console.log(printName()); // Output: John Doe
261+
```
262+
263+
Is example mein humne `person` object ka `fullName` method banaya hai jo `this.firstName` aur `this.lastName` ki madad se full name return karta hai. Fir humne `bind()` method ka use karke `printName` variable mein `person.fullName` ko bind kiya hai. Ab hum `printName()` ko call karte hai toh yeh `person.fullName()` ko call karega lekin `this` ka value `person` hi hoga.
264+
265+
Mujhe ummeed hai ki ab aapko bind method samajh mein aa gaya hoga!
266+
267+
### What is Immediately invoked function expression ?
268+
269+
Immediately Invoked Function Expression (IIFE) is a JavaScript function that is executed as soon as it's defined. In simple terms, it's a function that runs right away.
270+
271+
Example in JavaScript:
272+
273+
(function(){
274+
// Code to be executed immediately
275+
})();
276+
277+
In Hinglish language:
278+
279+
Immediately invoked function expression (IIFE) ek JavaScript function hai jo ki define hote hi execute ho jata hai. Saral bhasha me samjhe to ye ek function hai jo turant chal jata hai.
280+
281+
Udaharan JavaScript me:
282+
283+
(function(){
284+
// Code jo immediate taur par execute hoga
285+
})();
286+
287+
### What is Closure in javascript ?
288+
289+
Closure in JavaScript refers to the ability of a function to access variables from its outer lexical scope, even after the outer function has returned.
290+
291+
Ek closure tab hota hai jab ek function bahar ke variables aur functions ke references ko lekar apne andar use karta hai, aur phir wo function ussi state mein rehta hai jis mein usko define kiya gaya tha. Yeh bahar ke variables aur functions ke liye private scope create karta hai.
292+
293+
For example:
294+
295+
```
296+
function counter() {
297+
let count = 0;
298+
return function increment() {
299+
count++;
300+
console.log(count);
301+
}
302+
}
303+
304+
const c = counter();
305+
c(); // logs 1
306+
c(); // logs 2
307+
```
308+
309+
Iss code mein, `counter` function ek function `increment` ko return karta hai. `increment` function `count` variable ko access kar sakta hai, jo `counter` function ke lexical scope mein define kiya gaya hai. Jab `c` ko `counter` se invoke kiya jata hai, wo `increment` function ko return karta hai jismein `count` variable ki value increment ho jaati hai. Har baar jab `increment` function call kiya jata hai, wo `count` variable ki updated value ko print karta hai.
310+
311+
Iss tarah se, closure ka upyog karke hum private variables aur functions ko create kar sakte hai, jinka access sirf unhi functions ke through possible hai jismein wo define kiye gaye hai.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

‎notes/Hindi/61-Optional-chaining.md

Whitespace-only changes.

‎notes/Hindi/87-enhanced-object-literal.md

Whitespace-only changes.

0 commit comments

Comments
 (0)
Please sign in to comment.