Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2bc2cbb

Browse files
committed
adding lesson 8 and lesson 9 with comments updated in lesson 4-5
1 parent c1a579d commit 2bc2cbb

File tree

4 files changed

+98
-4
lines changed

4 files changed

+98
-4
lines changed

Lesson4-Loops.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ do{
2222
// Notes: myWords is a special type of varaiables called an array which will be coverd in detail in next lecture...
2323
//For now just assume it is a collection of same type values combined together like nouns/words in the below example.
2424

25-
//please see image forloop variations.png for more clear understanding of diifrent variations of for loop discussed below
25+
//please see image for loop variations.png for more clear understanding of driftnet variations of for loop discussed below
2626

2727
const myWords = ["car", "animal", "cart", "fan"];
2828
for (const word of myWords) {

Lesson5-Arrays.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ for(let lang of language)
2323
//shift() removes first element from array and returns it
2424
let fruit= fruitsArray.shift()
2525
console.log(fruit)
26-
//unshift() add element(s) at the starts af array
26+
//unshift() add element(s) at the start af array
2727
fruitsArray.unshift('watermelon', 'mango')
2828
//foreach() used to iteatae over an array
2929
fruitsArray.forEach(element => {
@@ -53,7 +53,7 @@ let anotherWords=['fine', 'sam']
5353
wordsArray=wordsArray.concat(anotherWords)
5454
console.log(wordsArray.concat('?'))
5555

56-
//index of - returns the first occurance of an element
56+
//index of - returns the first occurrence of an element
5757
let colors=['red','green', 'white']
5858
let index=colors.indexOf('green')
5959
console.log(index)
@@ -62,4 +62,4 @@ console.log(colors.indexOf('green',colors.indexOf('green')+1))
6262

6363
//includes returns true if multiples elements are passed then if if any one is found then it will retun true
6464
let nounArray=['boy','cat','elephant']
65-
console.log(nounArray.includes('elephant','diansour'));
65+
console.log(nounArray.includes('elephant','dinosaur'));

Lesson8-RestAndSpreadOperator.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// rest operator
2+
const printInfo = (firstName,lastName,age,...otherInfo)=>{
3+
console.log(`person has first name:${firstName}`);
4+
console.log(`person has last name: ${lastName}`);
5+
console.log(`person has age: ${age}`);
6+
logOtherInfo(otherInfo)
7+
//console.log(`person has other Info:${otherInfo}`)
8+
}
9+
const logOtherInfo = (otherInfo)=>{
10+
otherInfo.forEach(someInfo => {
11+
console.log(someInfo)
12+
});
13+
}
14+
15+
printInfo('steve' ,'jerrod' , 30, 'plays hockey' , 'likes Batman');
16+
//another way
17+
printInfo('micheal', 'frances' , 36 , ['plays soccer', 'likes superman'])
18+
19+
//spread operator (like un packing things)
20+
const someFruits=['apple','banana', 'orange']
21+
const moreFruits=['peach',...someFruits,'mango']
22+
console.log(moreFruits)// Output: ['grape', 'apple', 'banana', 'orange', 'pineapple']
23+
24+
//spread operator on objects
25+
const person = { name: 'John', age: 30 };
26+
const updatedPerson = {
27+
...person,
28+
city: 'New York' };
29+
console.log(updatedPerson);
30+
31+
//spread can be used to copy contents of an array
32+
const chocolateChipCookies = ["Chocolate Chip Cookie","Chocolate Chip Cookie","Chocolate Chip Cookie"];
33+
const oatmealCookies = ["Oatmeal Cookie", "Oatmeal Cookie"];
34+
let allCookies = [...chocolateChipCookies, ...oatmealCookies];
35+
console.log(allCookies);
36+
37+
//passing arguments in a function
38+
let personEssay = (firstName, lastName, age) =>
39+
`Person has first name ${firstName} last name ${lastName} and is ${age} years of age`;
40+
console.log(personEssay(...["steve", "jerrad", 13]));
41+

Lesson9-Destructuring.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// Destructuring in JavaScript is like taking apart a structured item (such as an array or object) and pulling out specific pieces that you want. It helps you easily extract values
2+
// from arrays or properties from objects and store them into individual variables.
3+
const fruits= ['apple','orange','banana']
4+
const [firstFruit,secondFruit,thirdFruit]=fruits
5+
console.log(`First Fruit:${firstFruit}`);
6+
console.log(`Second Fruit:${secondFruit}`)
7+
//Destructuring using the spread operator
8+
const languages=['Java','C#', 'Python','Ruby', 'Swift']
9+
const [java,c,...otherLanguages]= languages;
10+
console.log(java);
11+
console.log(c)
12+
otherLanguages.forEach(lang=>{
13+
console.log(lang);
14+
})
15+
16+
//Destructuring the objects
17+
const personInfo={
18+
personName:'Jhon',
19+
age:35,
20+
city:'London'
21+
}
22+
23+
const {personName,...otherInfo}=personInfo
24+
//Note we can't use foreach() here as for each forEach() works for arrays, not for objects.
25+
for(let key in otherInfo){
26+
console.log(otherInfo[key])
27+
}
28+
29+
const actor = {
30+
name: "Tom Hanks",
31+
age: 65,
32+
movies:["Forrest Gump", "Cast Away", "Saving Private Ryan"],
33+
};
34+
35+
const {name,...otherActorInfo}=actor
36+
//further destructuring
37+
console.log(...otherActorInfo.movies)
38+
39+
// Destructuring on Nested Objects
40+
const playerInfo={
41+
id: 1,
42+
profile: {
43+
playerName: 'Alice',
44+
location: {
45+
city: 'Moscow',
46+
country: 'Russia'
47+
}
48+
},
49+
50+
}
51+
const {id,profile:{playerName,location:{country}}}=playerInfo
52+
console.log(id)
53+
console.log(country)

0 commit comments

Comments
 (0)