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 fruits ="Fruits:apples, oranges, pears"; | |
| const regex = /(apples)/gd; | |
| const matches = [...fruits.matchAll(regex)]; | |
| console.log(matches[0]); |
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 person = Object.create(null); | |
| person.age = 21; | |
| if (Object.hasOwn(person, 'age')) { | |
| console.log(person.age); // true - works regardless of how the object was created | |
| } | |
| if (person.hasOwnProperty('age')){ // throws error - person.hasOwnProperty is not a function | |
| console.log('hasOwnProperty: ', person.age); | |
| } |
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 fruits = ['apples', 'oranges', 'pears']; | |
| console.log(fruits[fruits.length - 1]); // pears | |
| console.log(fruits.at(0)); // apples | |
| console.log(fruits.at(-1)); // pears |
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
| class User { | |
| username; | |
| #address; | |
| set #address(addr) { | |
| #address = addr; | |
| } | |
| get #address() { | |
| return #address; |