Skip to content

Commit b781fa4

Browse files
committed
adding Debouncing
2 parents 1d19fc7 + 8647a29 commit b781fa4

19 files changed

+453
-50
lines changed

Currying.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
//It is a process of taking a function with multiple arguments and turning
44
//it tinto a sequence of functions each with only a single argument
55

6-
function calculateVolume(Length)
6+
7+
function calculateVolume(length)
78
{
89
return function(breadth){
910
return function (height){
@@ -14,4 +15,4 @@ function calculateVolume(Length)
1415

1516
}
1617

17-
console.log(calculateVolume((2)(3))(5));
18+
console.log(calculateVolume(2)(3)(5));

Inheritance.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class surname {
2+
constructor() {
3+
console.log("kumari 💫");
4+
}
5+
}
6+
7+
class Name extends surname {
8+
constructor() {
9+
console.log("Riya");
10+
super();
11+
}
12+
}
13+
14+
const user = new Name();

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2023 Riya Kumari
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

OptionalChaining.js

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,20 @@ const user = {
55
street:" Road ",
66
city : "Patna" ,
77
state : "Bihar",
8-
zip : 4657890
9-
10-
}
11-
8+
zip : 4657890
9+
}
1210
}
11+
console.log(user.address.country?.pin); //undefined
1312

14-
console.log(user.address.country?.pin);
13+
//Optional chaining can be used to acess the elements of the array in JavaScript . It works in a similar way to acessing properties
14+
// of an object but using ?.[] instead of the ?. operator
15+
16+
const users = [
17+
{name : "Riya" , age: 20 },
18+
{
19+
name : "bebe" , age : 25},
20+
{
21+
name : "jenny", age : 30} ,
22+
];
23+
24+
console.log(users[3]?.age);

README.md

Lines changed: 216 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,110 @@
11
# JavaScript
2-
This repository contains a collection of daily JavaScript coding questions or concepts along with their solutions.
2+
This repository contains a collection of daily JavaScript coding questions or concepts along with their solutions.<br>
3+
And my daily learnings .
34

4-
<h3>JavaScript Concepts</h3>
5+
In the problem folder, you will find different questions of JavaScript Solved with Questions attached .
6+
<h3>JavaScript Concepts....</h3>
7+
8+
- [Implicit Type Coercion](#implicit-type-coercion)
9+
- [IIFE](#iife)
10+
- [Callback Function](#callback-function)
11+
- [Slice](#slice)
12+
- [Higher order Functions](#higher-order-functions)
13+
- [Currying](#currying)
14+
- [Call Apply Bind](#call-apply-bind)
15+
- [Optional Chaining](#optional-chaining)
16+
- [Inheritance](#inheritance)
17+
18+
<!--<a href="#Implicit Type Coercion"><li>Implicit Type Coercion</li></a>
19+
<li>IIFE</li>
20+
<li>Callback Function</li>
21+
<li>Slice</li>
22+
<li>Higher Order Functions</li>
23+
<li>Currying</li>
24+
<li>Call , Apply , Bind</li>
25+
<a href="#Optional chaining (?.)"><li>Optional chaining (?.)</li></a>-->
26+
<!--- [Optional Chaining](#Optional chaining (?.))
27+
[Markdown - Optional Chaining](#Optional chaining (?.))-->
28+
29+
30+
<ul>
31+
32+
33+
34+
# Implicit Type Coercion
35+
<p>Implicit type coercion in javascript is the automatic conversion of value from one data type to another. It takes place when the operands of an expression are of different data types.</p>
536
<ul>
37+
<li>String coercion</li>
38+
<p>String coercion takes place while using the ‘ + ‘ operator. When a number is added to a string, the number type is always converted to the string type</p>
39+
40+
```javascript
41+
var x = 3;
42+
var y = "3";
43+
x + y // Returns "33"
44+
```
45+
<p>When JavaScript sees that the operands of the expression x + y are of different types ( one being a number type and the other being a string type ), it converts the number type to the string type and then performs the operation. Since after conversion, both the variables are of string type, the ‘ + ‘ operator outputs the concatenated string “33” in the first example and “24Hello” in the second example.</p>
46+
<p> ‘ + ‘ operator when used to add two numbers, outputs a number. The same ‘ + ‘ operator when used to add two strings, outputs the concatenated string:</p>
47+
48+
```javascript
49+
50+
var name = "Riya";
51+
var surname = " Kumari";
52+
name + surname // Returns "Riya Kumari"
53+
```
54+
55+
<p> Type coercion also takes place when using the ‘ - ‘ operator, but the difference while using ‘ - ‘ operator is that, a string is converted to a number and then subtraction takes place.</p>
56+
57+
```javascript
58+
var x = 3;
59+
Var y = "3";
60+
x - y //Returns 0 since the variable y (string type) is converted to a number type
61+
```
62+
</ul>
63+
64+
65+
# IIFE
66+
<p>An IIFE (Immediately Invoked Function Expression) is a JavaScript function that runs as soon as it is defined</p>
67+
68+
```javascript
69+
// Regular Function.
70+
function Greet() {
71+
console.log("Welcome to the Readme.md");
72+
};
73+
// Execution of Regular Function.
74+
Greet();
75+
76+
// IIFE creation and execution.
77+
(function() {
78+
console.log("Welcome to Readme.md!");
79+
})();
80+
81+
82+
```
83+
<ul>
84+
<li>IIFEs have their own scope i.e. the variables you declare in the Function Expression will not be available outside the function.</li>
85+
<li>Similarly to other functions IIFEs can also be named or anonymous, but even if an IIFE does have a name it is impossible to refer/invoke it.</li>
86+
<li>IIFEs can also have parameters.</li>
87+
</ul>
88+
<ul>
89+
<br>
90+
<b>Use Cases Of IIFE</b>
91+
<li>Avoid polluting the global namespace </li>
92+
<li>To create closures</li>
93+
<li>Avoid conflict of variable names between libraries and programs.</li>
94+
</ul>
95+
96+
97+
98+
99+
100+
101+
102+
103+
104+
6105
<!-- 1 -->
7-
<li><b>Callback Function</b></li><p>A callback function is a function passed into another function as an argument, which is then invoked inside the outer function to complete some kind of routine or action.</p>
106+
# Callback Function
107+
<p>A callback function is a function passed into another function as an argument, which is then invoked inside the outer function to complete some kind of routine or action.</p>
8108

9109

10110
```javascript
@@ -24,7 +124,7 @@ This repository contains a collection of daily JavaScript coding questions or co
24124

25125
<!-- 2-->
26126

27-
<li><b>Slice</b></li>
127+
# Slice
28128
<!-- <p>The slice() method returns a <b>shallow copy</b>(<span style="color:orange;">A shallow copy of an arrays or object is one where they both have the same reference in memory. That means that if you change the shallow copy, it may or may not change the original copy.</span>) of a portion of an array into a new array object selected from start to end (end not included) where start and end represent the index of items in that array. The original array will not be modified.</p> -->
29129
<p>The Javascript arr.slice() method returns a new array containing a portion of the array on which it is implemented. The original remains unchanged.</p>
30130

@@ -51,9 +151,13 @@ console.log(a[1]);
51151
</ul>
52152
<br>
53153

154+
155+
156+
157+
54158
<!-- 3 -->
55159

56-
<li><b>Higher Order Functions</b></li>
160+
# Higher Order Functions
57161
<p>Functions that operate on other functions, either by taking them as arguments or by returning them, are called higher-order functions.</p>
58162

59163
```javascript
@@ -89,7 +193,7 @@ x() // Returns "Do something"
89193
<!-- 4 -->
90194

91195

92-
<li><b>Currying</b></li>
196+
# Currying
93197
<p>It is a technique in functional programming, that transforms the function of multiple arguments into several functions of a single argument in sequence. It is a method that takes one argument at a time and returns a new function that expects the next argument.</p>
94198

95199
```javascript
@@ -108,5 +212,111 @@ add(3)(4)
108212
<li>It helps us to avoid passing the same variable multiple times</li>
109213
<li>It is very useful in building modular and reusable code</li>
110214
</ul>
215+
<br>
216+
217+
# Call Apply Bind
218+
<ul>
219+
<li>Call</li>
220+
<p>It’s a predefined method in javascript.This method invokes a method (function) by specifying the owner object.<b>call()</b> method allows an object to use the method (function) of another object.</p>
221+
<p>This Concept is called <b>Function Borrowing</b></p>
222+
223+
224+
```javascript
225+
226+
var person = {
227+
age: 23,
228+
getAge: function(){
229+
return this.age;
230+
}
231+
}
232+
var person2 = {age: 54};
233+
person.getAge.call(person2);
234+
// Returns 54
235+
236+
```
237+
238+
<p>call() accepts arguments:</p>
239+
240+
```javascript
241+
242+
function saySomething(message){
243+
return this.name + " is " + message;
244+
}
245+
var person4 = {name: "Riya"};
246+
saySomething.call(person4, "awesome");
247+
// Returns "Riya is awesome"
248+
249+
```
250+
<h5>After looking at the above codes we can say that in layperson's terms, it helps you replace the value of <b>this</b> inside a function with whatever value you want.</h5>
251+
<p><b>Syntax</b></p>
252+
253+
```javascript
254+
call(objectInstance)
255+
call(objectInstance, arg1, /* …, */ argN)
256+
```
257+
258+
<li>Apply</li>
259+
<p>Apply is very similar to the call function. The only difference is that call() method takes arguments separately whereas, apply() method takes arguments as an <b>array</b>.</p>
260+
261+
262+
```javascript
263+
function saySomething(message){
264+
return this.name + " is " + message;
265+
}
266+
var person4 = {name: "Riya"};
267+
saySomething.apply(person4, ["awesome"]);
268+
```
269+
270+
<p>The best part about apply is we don’t need to take care of the number of arguments that are passed to the invoking function. Because of its dynamic and versatile nature, we can use it in complicated situations.</p>
271+
272+
<li>Bind</li>
273+
<p>This method returns a new function, where the value of “this” keyword will be bound to the owner object, which is provided as a parameter.</p>
274+
275+
```javascript
276+
function saySomething(message){
277+
return this.name + " is " + message;
278+
}
279+
var person4 = {name: "Riya"};
280+
let Greet = saySomething.bind(person4, "awesome");
281+
console.log(Greet());
282+
```
283+
284+
285+
<p>The only difference between the call and bind is that it gives you copy of the function which can be invoked later rather than directly invoking it .</p>
286+
</ul>
287+
288+
# Optional chaining
289+
<p>The ?. operator is like the . chaining operator, except that instead of causing an error if a reference is nullish (null or undefined), the expression short-circuits with a return value of undefined. When used with function calls, it returns undefined if the given function does not exist.
290+
The <b>optional chaining (?.)</b> operator accesses an object's property or calls a function. If the object accessed or function called using this operator is undefined or null, the expression short circuits and evaluates to undefined instead of throwing an error.</p>
291+
292+
# Inheritance
293+
294+
```javascript
295+
296+
class surname {
297+
constructor() {
298+
console.log("kumari 💫");
299+
}
300+
}
301+
302+
class Name extends surname {
303+
constructor() {
304+
console.log("Riya");
305+
super();
306+
}
307+
}
308+
309+
const user = new Name();
310+
```
311+
312+
Explanation :
313+
314+
```javascript
315+
const user = new Name();
316+
```
317+
318+
<p>
319+
This line creates an instance of the Name class, which triggers the constructor of the Name class. Inside the constructor, "Riya" is logged to the console, and then the super() method is called, which triggers the constructor of the surname class. In the surname constructor, "kumari 💫" is logged to the console.
320+
</p>
111321

112322
</ul>

Regular vs Arrow Function.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
const user= {
2+
name: "Riya Kumari",
3+
email: "my@email.com",
4+
updateName: function(name){
5+
this.name = name;
6+
},
7+
updateEmail: email => {
8+
this.email = email
9+
}
10+
}
11+
12+
user.updateName("Riyakumari57");
13+
user.updateEmail("new@email.com")
14+
console.log(user.name);
15+
console.log(user.email);
16+
17+
18+
19+
// The 'updateName' method is defined using a regular function expression (function(name) {...}).
20+
// Regular functions have their own 'this' context, and when invoked as a method of an object,
21+
// 'this' refers to the object that the method was called on. In this case, when 'updateName' is called,
22+
// 'this.name' refers to the name property of the user object.
23+
24+
25+
26+
// The 'updateEmail' method is defined using an arrow function (email => {...}).
27+
// Arrow functions, unlike regular functions, do not have their own 'this' context.
28+
// Instead, they inherit the 'this' value from the enclosing lexical scope.
29+
// In this case, the enclosing scope is the global scope (or the containing function scope, if applicable),
30+
// not the user object. Therefore, when 'updateEmail' is called, 'this.email' does not refer to the email property of the user object.

ReverseString.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
var string = 'Riya kumari is a nice girl'
1+
let string = 'Riya kumari is a nice girl'
22

3-
var reverseEntireSentence = reverseBySeparator(string, "");
4-
var reverseEachWord = reverseBySeparator(reverseEntireSentence, " ");
3+
let reverseEntireSentence = reverseBySeparator(string, "");
4+
let reverseEachWord = reverseBySeparator(reverseEntireSentence, " ");
55

6-
console.log(reverseEntireSentence);
7-
console.log(reverseEachWord);
6+
console.log(reverseEntireSentence);
7+
console.log(reverseEachWord);
88

9-
function reverseBySeparator(string, separator) {
9+
function reverseBySeparator(string, separator) {
1010
return string.split(separator).reverse().join(separator);
11-
}
11+
}

0 commit comments

Comments
 (0)