const obj = { a: 1 };
Object.seal(obj);
obj.b = 2;
console.log(obj.b);
const regex = /^(?!cat).+$/;
console.log(regex.test('cat'), regex.test('dog'), regex.test('category'));
const regex = /colou?r/;
console.log(regex.test('color'), regex.test('colour'), regex.test('colr'));
const regex = /(?<day>\d{2})-(?<month>\d{2})-(?<year>\d{4})/;
const str = '25-12-2020';
const { groups: { day, month, year } } = str.match(regex);
console.log(day, month, year);
function processData({ a = 10, b = 20 } = { a: 30 }) {
console.log(a, b);
}
processData({ a: 5 });
processData();
const arr = [1, 2];
arr.length = 0;
console.log(arr[0]);
const regex = /\d{2,}/;
console.log(regex.test('5'), regex.test('55'), regex.test('555'));
const arr = [...new Set([3, 1, 2, 3, 4])]
console.log(arr.length, arr[2])
const obj = {};
Object.defineProperty(obj, "prop", {
value: 42,
writable: false
});
obj.prop = 100;
console.log(obj.prop);
let javascript_tests = 1000
try {
javascript_tests = 550
} finally {
javascript_tests = 64
}
console.log(javascript_tests)
const regex = /\bcat\b/;
console.log(regex.test('concatenate'), regex.test('cat'), regex.test('scatter'));
const x = (() => {
try {
return 10;
} finally {
return 20;
}
})();
console.log(x);
const regex = /\D+/;
const str = '123abc456';
console.log(str.match(regex)[0]);
const arr = [1, 2, 3];
arr[-1] = 10;
console.log(arr.length, arr[-1]);
const regex = /^cat/gm;
const str = `dog
cat
bat`;
console.log(str.match(regex));
const parent = { name: 'John' };
const child = Object.create(parent);
child.age = 5;
Object.create()
позволяет создать новый объект, который наследует свойства и методы от родительского объекта parent
.const regex = /ba{2,3}n/;
console.log(regex.test('ban'), regex.test('baan'), regex.test('baaan'));
const set = new Set([1, 1, 2, 3, 4]);
console.log(set);
const regex = /(foo)(bar)/;
const str = 'foobar';
const match = str.match(regex);
console.log(match[0], match[1], match[2]);