├── bind-method.js ├── call-apply.js ├── compare-object.js ├── index.html ├── loop-object.js ├── method.js ├── object-create.js ├── properties.js ├── summary.js └── this.js /bind-method.js: -------------------------------------------------------------------------------- 1 | const kibria = { 2 | id: 101, 3 | money: 5000, 4 | name: 'RJ Kibria', 5 | treatDey: function (expense) { 6 | this.money = this.money - expense; 7 | console.log('here5555', this); 8 | return this.money; 9 | } 10 | } 11 | 12 | const heroBalam = { 13 | id: 102, 14 | money: 6000, 15 | name: 'Hero Balam' 16 | } 17 | const normalGolam = { 18 | id: 102, 19 | money: 8000, 20 | name: 'Normal Golam' 21 | } 22 | 23 | kibria.treatDey(100); 24 | const heroTreatDey = kibria.treatDey.bind(heroBalam); 25 | heroTreatDey(500); 26 | heroTreatDey(300); 27 | heroTreatDey(500); 28 | kibria.treatDey(400); 29 | const normalTreatDey = kibria.treatDey.bind(normalGolam); 30 | normalTreatDey(2000); -------------------------------------------------------------------------------- /call-apply.js: -------------------------------------------------------------------------------- 1 | const kibria = { 2 | id: 101, 3 | money: 5000, 4 | name: 'RJ Kibria', 5 | treatDey: function (expense, boksis, tax) { 6 | this.money = this.money - expense - boksis - tax; 7 | console.log('here5555', this); 8 | return this.money; 9 | } 10 | } 11 | 12 | const heroBalam = { 13 | id: 102, 14 | money: 6000, 15 | name: 'Hero Balam' 16 | } 17 | const normalGolam = { 18 | id: 102, 19 | money: 8000, 20 | name: 'Normal Golam' 21 | } 22 | //call 23 | kibria.treatDey.call(heroBalam, 500, 100, 50); 24 | kibria.treatDey.call(heroBalam, 300, 50, 30); 25 | 26 | kibria.treatDey.apply(heroBalam, [500, 100, 50]); 27 | kibria.treatDey.apply(heroBalam, [1000, 200, 100]); 28 | 29 | kibria.treatDey.apply(normalGolam, [700, 100, 70]) -------------------------------------------------------------------------------- /compare-object.js: -------------------------------------------------------------------------------- 1 | const first = { a: 1, b: 2 }; 2 | const second = { a: 1, b: 2 }; 3 | const third = first; 4 | 5 | if (first === third) { 6 | // console.log('objects are equal'); 7 | } 8 | else { 9 | // console.log('Objects are different'); 10 | } 11 | 12 | 13 | const first2 = { a: 1, b: 2, c: 2 }; 14 | const second2 = { b: 2, a: 1 }; 15 | console.log(JSON.stringify(first2)); 16 | console.log(JSON.stringify(second2)); 17 | if (JSON.stringify(first2) === JSON.stringify(second2)) { 18 | // console.log('objects are equal') 19 | } 20 | 21 | function compareObjects(obj1, obj2) { 22 | if (Object.keys(obj1).length !== Object.keys(obj2).length) { 23 | return false; 24 | } 25 | for (const prop in obj1) { 26 | if (obj1[prop] !== obj2[prop]) { 27 | return false; 28 | } 29 | } 30 | return true; 31 | } 32 | 33 | const isEqual = compareObjects(first2, second2); 34 | console.log(isEqual); -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | What the heck is this 9 | 10 | 11 | 12 |

What the heck is this!!!

13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /loop-object.js: -------------------------------------------------------------------------------- 1 | const bottle = { 2 | color: 'yellow', 3 | hold: 'water', 4 | price: 50, 5 | isCleaned: true 6 | }; 7 | /* 8 | for(let i = 0; i<10;i++){} 9 | for(const num of numbers){} // array 10 | for(const prop in student){} // object 11 | */ 12 | for (const prop in bottle) { 13 | // console.log(prop, bottle[prop]); 14 | } 15 | 16 | const keys = Object.keys(bottle); 17 | // console.log(keys); 18 | for (const prop of keys) { 19 | // console.log(prop, bottle[prop]); 20 | } 21 | 22 | // advanced 23 | const entries = Object.entries(bottle); 24 | // console.log(entries); 25 | // const [key, value] = ['color', 'yellow']; 26 | for (const [key, value] of Object.entries(bottle)) { 27 | console.log(key, value); 28 | } 29 | 30 | // 31 | // const arr = ['color', 'jeans', 'tom'] 32 | // arr['color'] -------------------------------------------------------------------------------- /method.js: -------------------------------------------------------------------------------- 1 | const student = { 2 | id: 101, 3 | money: 5000, 4 | name: 'RJ Kibria', 5 | major: 'mathematics', 6 | isRich: false, 7 | subjects: ['english', 'economics', 'math 101', 'calculus'], 8 | bestFriend: { 9 | name: 'kundu', 10 | major: 'mathematics' 11 | }, 12 | takeExam: function () { 13 | console.log(this.name, 'taking exam'); 14 | }, 15 | treatDey: function (expense, boksis) { 16 | this.money = this.money - expense - boksis; 17 | return this.money; 18 | } 19 | } 20 | 21 | student.takeExam(); 22 | const remaining1 = student.treatDey(900, 100); 23 | const remaining2 = student.treatDey(500, 50); 24 | console.log(remaining2); -------------------------------------------------------------------------------- /object-create.js: -------------------------------------------------------------------------------- 1 | // 1. using object literal 2 | const student = { name: 'Sakib AL Hasan', job: 'cricketer' }; 3 | // 2. constructor 4 | const person = new Object(); 5 | 6 | // 3. 7 | // const human = Object.create(null); 8 | const human = Object.create(student); 9 | // console.log(human.job); 10 | 11 | // 4. class 12 | class People { 13 | constructor(name, age) { 14 | this.name = name; 15 | this.age = age; 16 | } 17 | } 18 | const peop = new People('Manus', 12); 19 | // console.log(peop); 20 | 21 | // 5. function 22 | function Manus(name) { 23 | this.name = name; 24 | } 25 | const man = new Manus('kader'); 26 | console.log(man); -------------------------------------------------------------------------------- /properties.js: -------------------------------------------------------------------------------- 1 | const bottle = { 2 | color: 'yellow', 3 | hold: 'water', 4 | price: 50, 5 | isCleaned: true 6 | }; 7 | // getting all properties names 8 | const keys = Object.keys(bottle); 9 | // console.log(keys); 10 | // get all values 11 | const values = Object.values(bottle); 12 | // console.log(values); 13 | const pairs = Object.entries(bottle); 14 | // console.log(pairs); 15 | // Object.seal(bottle); 16 | Object.freeze(bottle); 17 | bottle.price = 100; 18 | bottle.height = 16; 19 | delete bottle.isCleaned; 20 | console.log(bottle); -------------------------------------------------------------------------------- /summary.js: -------------------------------------------------------------------------------- 1 | const pen = { 2 | brand: 'econo', 3 | price: 10, 4 | writePoem: function (food) { 5 | console.log(food); 6 | } 7 | } 8 | const keys = Object.keys(pen); 9 | const values = Object.values(pen); 10 | 11 | for (const key in pen) { 12 | console.log(pen[key]); 13 | } 14 | 15 | const a = { a: 1 }; 16 | const b = { a: 1 }; 17 | const c = a; 18 | 19 | if (a === b) { 20 | 21 | } 22 | // optional 23 | const aBounded = pen.writePoem.bind(a); 24 | aBounded(); 25 | 26 | // this -------------------------------------------------------------------------------- /this.js: -------------------------------------------------------------------------------- 1 | // console.log(this); 2 | const kibria = { 3 | id: 101, 4 | money: 5000, 5 | name: 'RJ Kibria', 6 | treatDeyArrow: () => { 7 | console.log(this); 8 | }, 9 | treatDeyInside: function () { 10 | const myArrow = () => console.log(this); 11 | myArrow(); 12 | }, 13 | treatDey: function (expense) { 14 | this.money = this.money - expense; 15 | console.log('here5555', this); 16 | return this.money; 17 | } 18 | } 19 | 20 | const heroBalam = { 21 | id: 102, 22 | money: 6000, 23 | name: 'Hero Balam' 24 | } 25 | 26 | function add() { 27 | console.log(this); 28 | } --------------------------------------------------------------------------------