|
| 1 | +const user = { |
| 2 | + username: "kalpjeet", |
| 3 | + price: 999, |
| 4 | + welcomeMessage: function(){ |
| 5 | + console.log(`${this.username} , welcome to website`); |
| 6 | + console.log(this);// |
| 7 | +// kalpjeet , welcome to website |
| 8 | +// { |
| 9 | +// username: 'kalpjeet', |
| 10 | +// price: 999, |
| 11 | +// welcomeMessage: [Function: welcomeMessage] |
| 12 | +// } |
| 13 | +// sam , welcome to website |
| 14 | +// { |
| 15 | +// username: 'sam', |
| 16 | +// price: 999, |
| 17 | +// welcomeMessage: [Function: welcomeMessage] |
| 18 | +// } |
| 19 | + } |
| 20 | +} |
| 21 | +user.welcomeMessage()//kalpjeet , welcome to website |
| 22 | +user.username = "sam" |
| 23 | +user.welcomeMessage()//sam , welcome to website |
| 24 | +console.log(this);//{} |
| 25 | + |
| 26 | +function chai(){ |
| 27 | + let username ="kalpjeet" |
| 28 | + console.log(this); |
| 29 | + //console.log(this.username) //undefined |
| 30 | +} |
| 31 | +chai() |
| 32 | +/* <ref *1> Object [global] { |
| 33 | + global: [Circular *1], |
| 34 | + clearImmediate: [Function: clearImmediate], |
| 35 | + setImmediate: [Function: setImmediate] { |
| 36 | + Symbol(nodejs.util.promisify.custom): [Getter] |
| 37 | + }, |
| 38 | + clearInterval: [Function: clearInterval], |
| 39 | + clearTimeout: [Function: clearTimeout], |
| 40 | + setInterval: [Function: setInterval], |
| 41 | + setTimeout: [Function: setTimeout] { |
| 42 | + Symbol(nodejs.util.promisify.custom): [Getter] |
| 43 | + }, |
| 44 | + queueMicrotask: [Function: queueMicrotask], |
| 45 | + structuredClone: [Function: structuredClone], |
| 46 | + atob: [Function: atob], |
| 47 | + btoa: [Function: btoa], |
| 48 | + performance: [Getter/Setter], |
| 49 | + fetch: [Function: fetch], |
| 50 | + crypto: [Getter], |
| 51 | + navigator: [Getter] |
| 52 | +} */ |
| 53 | + |
| 54 | +// const chai = function(){ |
| 55 | +// let username ="kalpjeet" |
| 56 | +// console.log(this.username) //undefined |
| 57 | +// } |
| 58 | + |
| 59 | +// const chai = () =>{ |
| 60 | +// let username = "kalpjeet" |
| 61 | +// console.log(this.username);//undefined |
| 62 | +// console.log(this);//{} |
| 63 | +// } |
| 64 | +//chai() |
| 65 | + |
| 66 | +const addTwo = (num1, num2) => { |
| 67 | + return num1+num2 |
| 68 | +} |
| 69 | +console.log(addTwo(4, 7))//11 |
| 70 | + |
| 71 | +//const addTwo = (num1, num2) => num1 + num2 |
| 72 | +//console.log(addTwo(4, 7))//11 |
| 73 | + |
| 74 | +const addTwo3 = (num1, num2) => ({username: "hitesh"}) |
| 75 | +console.log(addTwo3(3,4))//{ username: 'hitesh' } |
| 76 | + |
| 77 | +const myArray = [2, 5, 3, 7, 8] |
| 78 | +myArray.forEach(function () {}) |
| 79 | +myArray.forEach(() => {}) |
0 commit comments