This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const user = { | |
| firstName: 'Akash', | |
| lastName: 'Rajvanshi', | |
| fullname: function () { // Method | |
| return `${this.firstName} ${this.lastName}` | |
| } | |
| }; | |
| console.log(user.fullname()) // Akash Rajvanshi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function sayName(firstName, lastName) { | |
| console.log(`${firstName} ${lastName}`) | |
| } | |
| sayName('Akash', 'Rajvanshi') // Akash Rajvanshi | |
| // We can also call the function through call. | |
| // first Parameter passed into the function call replaces the this context. | |
| // Other values passed into the functions behave as normal agrguments | |
| sayName.call(null, 'Akash', 'Rajvanshi') // Akash Rajvanshi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const numbers = [1, 2, 3] // Array | |
| // Normal Method | |
| const newArray = numbers.slice() | |
| console.log(newArray) // [1, 2, 3] | |
| // Another Method | |
| const anotherNewArray = Array.prototype.slice.call(numbers) | |
| console.log(anotherNewArray) // [1, 2, 3] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function sayName (firstName, lastName) { | |
| console.log(`${firstName} ${lastName}`) | |
| } | |
| sayName.apply(null, ['Akash', 'Rajvanshi']) // Akash Rajvanshi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function sayName (firstName, lastName) { | |
| console.log(`${firstName} ${lastName}`) | |
| } | |
| const sayMyName = sayName.bind(null, 'Akash', 'Rajvanshi') | |
| sayMyName() // Akash Rajvanshi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const obj = { | |
| 'Can be any Number!': 5832 | |
| }; | |
| console.log(obj['Can be any Number!']) // 5832 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const user = { | |
| firstName: 'Akash', | |
| lastName: 'Rajvanshi', | |
| fullname: function () { | |
| return `${this.firstName} ${this.lastName}` | |
| } | |
| }; | |
| console.log(user['first' + 'Name']) // Akash |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const user = { | |
| fullName: function () { | |
| return `Akash` | |
| } | |
| }; | |
| console.log(user['fullName']()) //Akash |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const user = { | |
| firstName: 'Akash', | |
| showDetails: function () { | |
| return `${this.firstName} ${this.lastName}` | |
| } | |
| }; | |
| user['lastName'] = 'Rajvanshi' | |
| console.log(Object.keys(user)) // [ 'firstName', 'showDetails', 'lastName' ] | |
| console.log(user.showDetails()) // Akash Rajvanshi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| console.log(delete user['lastName']) // true | |
| console.log(Object.keys(user)) // [ 'firstName', 'showDetails' ] |