├── recap.js ├── class.js ├── map.js ├── more-map.js ├── filter-find.js ├── chaining.js ├── destructuring.js └── inheritance.js /recap.js: -------------------------------------------------------------------------------- 1 | // 1. let and const 2 | const hubby = 'Omor Sani'; 3 | let phone = 'iphone 15'; 4 | phone = 'Samsung Galaxy S17'; 5 | // 2. default 6 | // 5. spread or three dots (...) 7 | function maxNumber(array = []) { 8 | const max = Math.max(...array); 9 | return max; 10 | } 11 | const biggest = maxNumber(); 12 | console.log(biggest); 13 | // 3. template string 14 | const myNotes = `I am mojnu of ${hubby}. I have a ${phone}.` 15 | console.log(myNotes); 16 | 17 | // 4. arrow function 18 | // function square(x) { 19 | // return x * x; 20 | // } 21 | const square = x => x * x; 22 | console.log(square(9)); -------------------------------------------------------------------------------- /class.js: -------------------------------------------------------------------------------- 1 | class Support { 2 | name; 3 | designation = 'Support Web Dev'; 4 | address = 'BD'; 5 | constructor(name, address) { 6 | this.name = name; 7 | this.address = address; 8 | } 9 | startSession() { 10 | console.log(this.name, 'start a support session'); 11 | } 12 | } 13 | 14 | const aamir = new Support('Aamir Khan', 'BD'); 15 | const salman = new Support('Solaiman Khan', 'Dubai'); 16 | const sharuk = new Support('SRK Khan', 'Dubai'); 17 | const akshay = new Support('Akshay Kumar', 'Dubai'); 18 | aamir.startSession(); 19 | salman.startSession(); 20 | console.log(aamir, salman, sharuk, akshay); 21 | // console.log(salman); -------------------------------------------------------------------------------- /map.js: -------------------------------------------------------------------------------- 1 | const numbers = [4, 6, 8, 10]; 2 | const output2 = []; 3 | 4 | // function doubleOld(number) { 5 | // return number * 2; 6 | // } 7 | 8 | const doubleIt = number => number * 2; 9 | 10 | for (const number of numbers) { 11 | const result = doubleIt(number); 12 | output2.push(result); 13 | } 14 | // console.log(output2); 15 | 16 | // 1. loop through each element 17 | // 2. for each element call the provided function 18 | // 3. result for each element will be stored in an array 19 | 20 | // const output = numbers.map(doubleIt); 21 | // const output = numbers.map(number => number * 2); 22 | const output = numbers.map(x => x * 2); 23 | // console.log(output); 24 | 25 | const squares = numbers.map(x => x * x); 26 | console.log(squares); -------------------------------------------------------------------------------- /more-map.js: -------------------------------------------------------------------------------- 1 | const friends = ['Tom Hanks', 'Tom Cruise', 'Tom Brady', 'Tom Solaiman']; 2 | 3 | const fLengths = friends.map(friend => friend.length); 4 | // console.log(fLengths); 5 | 6 | const products = [ 7 | { name: 'water bottle', price: 50, color: 'yellow' }, 8 | { name: 'mobile phone', price: 15000, color: 'black' }, 9 | { name: 'smart watch', price: 3000, color: 'black' }, 10 | { name: 'sticky note', price: 30, color: 'pink' }, 11 | { name: 'water glass', price: 3, color: 'white' } 12 | ]; 13 | const productNames = products.map(product => product.name); 14 | const productPrices = products.map(product => product.price); 15 | // products.map(product => console.log(product)); 16 | products.forEach(product => console.log(product)); 17 | // console.log(productPrices); -------------------------------------------------------------------------------- /filter-find.js: -------------------------------------------------------------------------------- 1 | const numbers = [5, 13, 7, 41, 30, 5, 2, 19]; 2 | const bigNumbers = numbers.filter(number => number > 20); 3 | const smallNumbers = numbers.filter(number => number < 10); 4 | // console.log(smallNumbers); 5 | 6 | const products = [ 7 | { name: 'water bottle', price: 50, color: 'yellow' }, 8 | { name: 'mobile phone', price: 15000, color: 'black' }, 9 | { name: 'smart watch', price: 3000, color: 'black' }, 10 | { name: 'sticky note', price: 30, color: 'pink' }, 11 | { name: 'water glass', price: 3, color: 'white' } 12 | ]; 13 | 14 | const expensive = products.filter(product => product.price > 100); 15 | // console.log(expensive); 16 | const blacks = products.filter(product => product.color == 'pink'); 17 | // console.log(blacks); 18 | 19 | const whiteItem = products.find(product => product.color == 'black'); 20 | console.log(whiteItem); -------------------------------------------------------------------------------- /chaining.js: -------------------------------------------------------------------------------- 1 | // declare variable based on the name of an object property 2 | const myObject = { x: 2, y: 50, z: 600, a: 25, b: 68 }; 3 | const { x, b } = myObject; 4 | // console.log('myObject.p', myObject?.p?.q); 5 | 6 | // destructuring array 7 | const [p, q] = [45, 37, 91, 86]; 8 | // console.log(p, q); 9 | 10 | const [best, faltu] = ['momotaj', 'poroshi']; 11 | // console.log(best, faltu); 12 | const { sky, color, money } = { sky: 'blue', soil: 'matti', color: 'red', money: 500 }; 13 | 14 | //chaining 15 | 16 | const company = { 17 | name: 'GP', 18 | ceo: { id: 1, name: 'ajmol', food: 'fuchka' }, 19 | web: { 20 | work: 'website development', 21 | employee: 22, 22 | framework: 'react', 23 | tech: { 24 | first: 'html', 25 | second: 'css', 26 | third: 'js' 27 | } 28 | }, 29 | }; 30 | 31 | console.log(company?.web?.tech?.third); 32 | console.log(company?.backend?.tech.third); -------------------------------------------------------------------------------- /destructuring.js: -------------------------------------------------------------------------------- 1 | const fish = { id: 58, name: 'King Hilsha', price: 9000, phone: '01717555555555', address: 'Chandpur', dress: 'silver' }; 2 | 3 | // const phone = fish.phone; 4 | // const price = fish.price; 5 | // const dress = fish.dress; 6 | // const id = fish.id; 7 | 8 | const { phone, price, dress, id } = fish; 9 | 10 | // console.log(phone, price); 11 | // console.log(phone, id); 12 | // console.log(phone, dress); 13 | // console.log(phone, price); 14 | // console.log(phone); 15 | 16 | 17 | const company = { 18 | name: 'GP', 19 | ceo: { id: 1, name: 'ajmol', food: 'fuchka' }, 20 | web: { 21 | work: 'website development', 22 | employee: 22, 23 | framework: 'react', 24 | tech: { 25 | first: 'html', 26 | second: 'css', 27 | third: 'js' 28 | } 29 | }, 30 | }; 31 | 32 | // const work = company.web.work; 33 | // const framework = company.web.framework; 34 | const { work, framework } = company.web; 35 | const { food } = company.ceo; 36 | const { second, third } = company.web.tech; 37 | console.log(work, framework, food); -------------------------------------------------------------------------------- /inheritance.js: -------------------------------------------------------------------------------- 1 | class TeamMember { 2 | name; 3 | address = 'BD'; 4 | constructor(name, address) { 5 | this.name = name; 6 | this.address = address; 7 | } 8 | } 9 | 10 | class Support extends TeamMember { 11 | groupSupportTime; 12 | designation = 'Support Web Dev'; 13 | constructor(name, address, time) { 14 | super(name, address) 15 | this.groupSupportTime = time; 16 | } 17 | startSession() { 18 | console.log(this.name, 'start a support session'); 19 | } 20 | } 21 | 22 | class StudentCare extends TeamMember { 23 | designation = 'Care Web Dev'; 24 | buildARoutine(student) { 25 | console.log(this.name, 'Build a routine for', student); 26 | } 27 | } 28 | 29 | class NeptuneDev extends TeamMember { 30 | codeEditor; 31 | designation = 'Neptune App Dev'; 32 | constructor(name, address, editor) { 33 | super(name, address); 34 | this.codeEditor = editor; 35 | } 36 | releaseApp(version) { 37 | console.log(this.name, 'release app version', version); 38 | } 39 | } 40 | 41 | const aamir = new Support('Aamir Khan', 'BD', 11); 42 | const salman = new Support('Solaiman Khan', 'Dubai', 4); 43 | const sharuk = new Support('SRK Khan', 'Dubai', 9); 44 | const akshay = new Support('Akshay Kumar', 'Dubai', 11); 45 | 46 | const alia = new StudentCare('Alia Bhatt', 'Mumbai'); 47 | const ash = new NeptuneDev('Ash', 'Mumbai', 'Android studio'); 48 | ash.releaseApp('1.4.5'); 49 | console.log(ash.name); --------------------------------------------------------------------------------