Skip to content

Commit 0639a8e

Browse files
authored
Merge pull request #1 from Swap76/master
Update
2 parents 3f8d09c + 9c48544 commit 0639a8e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+2646
-298
lines changed

.eslintrc.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ module.exports = {
66
"quotes": ["error", "double"],
77
"semi": ["error", "always"],
88
"eol-last": ["error", "never"],
9-
"no-multiple-empty-lines": ["error", { max: 1 }]
9+
"no-multiple-empty-lines": ["error", { max: 1 }],
10+
"no-var": ["error"]
1011
}
1112
};

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
node_modules
22
package-lock.json
33
docs/_sidebar.md
4+
.DS_Store
Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,28 @@
11
let a = () => {
22
// This is arrow function came new in ES6
3+
//It assigns the function to variable a as the identifier with let instead and adds arrows before the curly braces.
4+
35
};
46

7+
8+
let multiply = (num) => num * num
9+
10+
//arrow functions also works without curly braces {} and can directly write expression after the arrows
11+
// this is known as concise body as opposed to a block body (with {});
12+
//cannot be used with if statements, or an error will appear since it only takes one expression;
13+
//ternary operators can be used with arrow functions as a more concise way to write if statements
14+
15+
16+
517
let info = {
618
firstName: "Swapnil",
719
lastName: "Shinde",
820
getFullName: () => {
9-
return(`My name is ${this.firstName} ${this.lastName}`); // Arrow functions don't have "this" property
21+
return (`My name is ${this.firstName} ${this.lastName}`); // Arrow functions don't have "this" property
1022
}
1123
}
24+
//not having this. binding means it also cannot be called with new and used as a constructor
25+
1226

1327
console.log(info.getFullName());
1428
// Output My name is undefined undefined that's why we don't use this with arrow function
@@ -17,7 +31,7 @@ let newInfo = {
1731
firstName: "Swapnil",
1832
lastName: "Shinde",
1933
getFullName: () => {
20-
return(`My name is ${newInfo.firstName} ${newInfo.lastName}`); // If we are using arrow function then directly use the variables as shown
34+
return (`My name is ${newInfo.firstName} ${newInfo.lastName}`); // If we are using arrow function then directly use the variables as shown
2135
}
2236
}
2337

@@ -31,32 +45,42 @@ class Student {
3145
}
3246

3347
getName = () => {
34-
return this.name;
48+
return this.name;
3549
}
3650
}
3751

3852
console.log((new Student).getName()) // Gives error for node versions before 12.4.0(Approx) SyntaxError: Unexpected token =
3953

4054
class StudentInfo {
4155

42-
constructor (firstName,lastName, age, branch, college){
43-
this.firstName = firstName;
56+
constructor(firstName, lastName, age, branch, college) {
57+
this.firstName = firstName;
4458
this.lastName = lastName;
45-
this.age = age;
59+
this.age = age;
4660
this.branch = branch;
4761
this.college = college;
4862
};
4963

5064
getFullName = () => { // Returns full name using string interpolation
51-
return(`My name is ${this.firstName} ${this.lastName}`); // If we are using arrow function then directly use the variables as shown
65+
return (`My name is ${this.firstName} ${this.lastName}`); // If we are using arrow function then directly use the variables as shown
5266
};
5367

5468
getBranch = () => { // Returns Branch
55-
return(this.branch);
69+
return (this.branch);
5670
};
5771

5872
}
5973

60-
let Swapnil = new StudentInfo("Swapnil", "Shinde",19, "Computer", "Sies"); // This way we can create new objects with arguments
74+
let Swapnil = new StudentInfo("Swapnil", "Shinde", 19, "Computer", "Sies"); // This way we can create new objects with arguments
75+
76+
console.log(Swapnil.getFullName()); // Output My name is Swapnil Shinde
77+
78+
//settimeout without arrow function
79+
setTimeout(function () {
80+
console.log("hello world");
81+
}, 1000);
6182

62-
console.log(Swapnil.getFullName()); // Output My name is Swapnil Shinde
83+
//settimeout with arrow function
84+
setTimeout(() => {
85+
console.log("hello world");
86+
}, 0); //arrow functions provide better readability

JavaScript_Advance/callback.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ transformNumber(10, (num) => {
6262
* passed to the `resolve()` function, will get passed to the function passed to `.then()`
6363
* function. Look at the following example from MDN official documents:
6464
*/
65-
var p1 = new Promise((resolve, reject) => {
65+
const p1 = new Promise((resolve, reject) => {
6666
resolve("Success!");
6767
// or
6868
// reject(new Error("Error!"));

JavaScript_Advance/cookies.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ console.log("Simple usage:" + document.cookie);
66
// #2 Get a cookie with the name 'actor'
77
document.cookie = "movie=Jungle Book";
88
document.cookie = "actor=Balu";
9-
var cookieValue = document.cookie.replace(/(?:(?:^|.*;\s*)actor\s*\=\s*([^;]*).*$)|^.*$/, "$1");
9+
const cookieValue = document.cookie.replace(/(?:(?:^|.*;\s*)actor\s*\=\s*([^;]*).*$)|^.*$/, "$1");
1010
console.log("Cookie with the name 'actor':" + cookieValue);
1111

1212
// #3 Set cookie and execute code only once if cookie doesn't exist yet

JavaScript_Advance/do_while_loop.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ do {
1010
1111
*/
1212

13-
var n = 1;
13+
let n = 1;
1414

1515
do {
1616
console.log("n is less than 6. n = " + n);

JavaScript_Advance/event_loop.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,14 @@ setTimeout(() => {
44

55
console.log("Last statement"); // This statement gets printed first
66

7-
// This enables the non blocking using event based management
7+
// This enables the non blocking using event based management
8+
9+
console.log("a");
10+
setTimeout(() => {
11+
console.log("b");
12+
}, 2000);
13+
console.log("c");
14+
setTimeout(() => {
15+
console.log("d");
16+
}, 0);
17+
// except answer : a , c , d , b

JavaScript_Advance/filtering_array.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,19 @@ const animals = ["cats", "dogs", "bunnies", "birds"];
22

33
const start_with_b = animals.filter(name => name.indexOf("b") === 0);
44

5-
console.log(start_with_b); // ['bunnies', 'birds']
5+
console.log(start_with_b); // ['bunnies', 'birds']
6+
7+
// function of filter (basic callback for filter)
8+
const arr = [1, 3, 42, 2, 4, 5];
9+
function filter (array, callback) {
10+
const callback_list = [];
11+
for (const i of array) {
12+
callback_list.push(callback(i));
13+
}
14+
return callback_list;
15+
}
16+
// modifyable callback function
17+
function callback (num) {
18+
return Math.pow(num, 2);
19+
}
20+
console.log(filter(arr, callback));

JavaScript_Advance/generators.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
Generators are functions with the possibility of exit and subsequent entry.
3+
Their execution context (variable values) is preserved on subsequent inputs.
4+
*/
5+
6+
// Let's consider a simple example:
7+
function* myGenerator() {
8+
yield 5
9+
yield 6
10+
}
11+
12+
// In the example above, we wrote a simple generator function with asteriks(*) notation.
13+
// Next to the yield we put values that are going to be extracted from the function
14+
// In order to extract them one by one, we should at first call myGenerator function
15+
16+
const gen = myGenerator()
17+
18+
// The returning value of myGenerator function is a object-iterator. It has next() method
19+
// Which we may call to get the current generator function value:
20+
21+
gen.next().value // 5
22+
23+
// We get the value field of 'next' method's returning value, wich is an object as well
24+
// Let's call this again in order to get the next value:
25+
26+
gen.next().value // 6
27+
28+
// After we iterate through all the values, the next value is going to be undefined.
29+
30+
gen.next().value // undefined.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Getting values of environment variables
2+
// For example, getting username of machine
3+
const ENV_VARIABLE_KEY = "USER";
4+
5+
const ENV_VARIABLE_VALUE = process.env[ENV_VARIABLE_KEY];
6+
7+
console.log(ENV_VARIABLE_VALUE);

0 commit comments

Comments
 (0)