try {
try {
// Creating a custom error type
class CustomError extends Error {
constructor(message) {
super(message);
this.name = "CustomError";
}
}
const fn = () => {
throw new CustomError("Something went wrong");
};
try {
fn();
} catch (e) {
throw new TypeError("Type error occurred");
}
} catch (e) {
console.log(e instanceof Error, e.name, e instanceof TypeError);
}
} catch (e) {
console.log("Outer catch", e.message);
}
Ответ:
JavaScript test | #JavaScript
Please open Telegram to view this post
VIEW IN TELEGRAM
function X() {}
X.prototype.getValue = function() {
return this.value;
};
function Y() {
this.value = 42;
}
Y.prototype = Object.create(X.prototype);
Y.prototype.constructor = Y;
var y = new Y();
console.log(y.getValue());
Ответ:
JavaScript test | #JavaScript
Please open Telegram to view this post
VIEW IN TELEGRAM
function mystery() {
try {
throw new Error('Oops');
return 'A';
} catch (err) {
return 'B';
} finally {
return 'C';
}
}
function wrapper() {
try {
return mystery();
} finally {
console.log('D');
}
}
console.log(wrapper());
Ответ:
JavaScript test | #JavaScript
Please open Telegram to view this post
VIEW IN TELEGRAM
function highlight(strings, ...values) {
return strings.reduce((result, str, i) => {
const value = values[i] ? `<span>${values[i]}</span>` : '';
return result + str + value;
}, '');
}
const language = 'JavaScript';
const years = 10;
const result = highlight`I have been coding in ${language} for ${years} years`;
console.log(result);
Ответ:
Please open Telegram to view this post
VIEW IN TELEGRAM
let a = 1;
let b = new Number(1);
let c = '1';
console.log(a == b);
console.log(a === b);
console.log(b == c);
Ответ:
Please open Telegram to view this post
VIEW IN TELEGRAM
This media is not supported in your browser
VIEW IN TELEGRAM
Новая сетка Telegram-каналов CodeGuard — собрана для твоего роста в IT!
📱 Front и топ инсайды IT-сферы
t.me/CodeGuard_SciencePop
🖥 Книги, курсы, утилиты и гайды
t.me/CodeGuard_Academy
📱 Обучение и задачи по Python
t.me/CodeGuard_Python
🤔 InfoSec & Хакинг
t.me/CodeGuard_PySec
👩💻 Знания и навыки Linux & Bash
t.me/CodeGuard_Linux
💼 Фриланс, карьера и работа IT
t.me/CodeGuard_VacancyIT
📌 Инструменты, гайды, шпаргалки, тренажеры и практические гайды.
t.me/CodeGuard_SciencePop
t.me/CodeGuard_Academy
t.me/CodeGuard_Python
t.me/CodeGuard_PySec
t.me/CodeGuard_Linux
t.me/CodeGuard_VacancyIT
Please open Telegram to view this post
VIEW IN TELEGRAM
class EventEmitter {
constructor() {
this.events = {};
}
on(event, callback) {
this.events[event] = this.events[event] || [];
this.events[event].push(callback);
return this;
}
emit(event, data) {
if (this.events[event]) {
this.events[event].forEach(cb => cb(data));
}
return this;
}
}
const emitter = new EventEmitter();
emitter.on('test', x => console.log(x * 2))
.on('test', x => console.log(x + 5))
.emit('test', 10);
Ответ:
JavaScript test | #JavaScript
Please open Telegram to view this post
VIEW IN TELEGRAM
Telegram
JavaScript test
Javascript и все что с ним связано
Ссылка: @Portal_v_IT
Сотрудничество: @oleginc
Ссылка: @Portal_v_IT
Сотрудничество: @oleginc
const weakMap = new WeakMap();
const obj1 = {};
const obj2 = { key: 'value' };
weakMap.set(obj1, obj2);
const result = weakMap.get(obj1).key.split('').reverse().join('');
console.log(result);
Ответ:
Please open Telegram to view this post
VIEW IN TELEGRAM
function Person(name) {
this.name = name;
this.sayName = () => console.log(this.name);
}
const person1 = new Person('David');
const person2 = { name: 'Not David', sayName: person1.sayName };
person2.sayName();
Ответ:
Please open Telegram to view this post
VIEW IN TELEGRAM
const obj = {
x: 10,
foo() {
setTimeout(function() {
console.log(this.x);
}, 1000);
}
};
obj.foo();
Ответ:
Please open Telegram to view this post
VIEW IN TELEGRAM
const person = {
name: "John",
greet: function() {
const getMessage = () => `Hello, ${this.name}`;
return getMessage();
}
};
console.log(person.greet());
Ответ:
Please open Telegram to view this post
VIEW IN TELEGRAM
const map = new Map([
['a', 1],
['b', 2],
['c', 3]
]);
const key = { id: 'key' };
map.set(key, 4);
map.set(key, 5);
const result = [];
result.push(map.get('a'));
result.push(map.get(key));
result.push(map.size);
result.push(map.has({ id: 'key' }));
console.log(result);
Ответ:
JavaScript test | #JavaScript
Please open Telegram to view this post
VIEW IN TELEGRAM
const obj = { a: 1, b: { c: 2 } };
const frozen = Object.freeze(obj);
frozen.a = 99;
frozen.b.c = 88;
frozen.d = 77;
const sealed = Object.seal({ x: 10, y: 20 });
sealed.x = 30;
sealed.z = 40;
delete sealed.y;
console.log(obj.a, obj.b.c, obj.d);
console.log(sealed.x, sealed.y, sealed.z);
Ответ:
JavaScript test | #JavaScript
Please open Telegram to view this post
VIEW IN TELEGRAM
const promise1 = Promise.resolve(10);
const promise2 = promise1.then(x => x * 2);
const promise3 = promise2.then(x => {
console.log(x);
return x + 5;
});
const promise4 = promise2.then(x => {
console.log(x);
return x * 3;
});
Promise.all([promise3, promise4]).then(results => {
console.log(results);
});
Ответ:
JavaScript test | #JavaScript
Please open Telegram to view this post
VIEW IN TELEGRAM
let obj1 = { name: 'Sarah' };
let obj2 = { name: 'Mike' };
let obj3 = { ref: obj1 };
obj1.circular = obj1;
obj2.partner = obj3;
obj3.partner = obj2;
let weakMap = new WeakMap();
weakMap.set(obj1, 'data1');
weakMap.set(obj2, 'data2');
obj1 = null;
obj2 = null;
console.log(weakMap.has(obj3.ref));
console.log(obj3.partner.name);
Ответ:
JavaScript test | #JavaScript
Please open Telegram to view this post
VIEW IN TELEGRAM
Forwarded from Романцев768 | Romancev768
Розыгрыш iPhone 17 Pro и лучших AirPods!
С каналом Костыль разыгрываем 2 отличных приза:
Призы
➡️ iPhone 17 Pro — лучший iPhone, универсального размера. Цвет выберет победитель
➡️ AirPods Pro 3 — наушники получит победитель под номером 2
Условия:
• подписаться на @Romancev768
• подписаться на @kostylofficial
• нажать на кнопку «Участвовать» под этим постом.
Двух победителей выберет рандомайзер.
Когда итоги?
В пятницу, 19 декабря, в 18:00
Где итоги?
В этом посте, вы его читаете, все итоги подводятся в постах с кнопкой «Участвовать».
Как получить?
Доставим в ближайшее отделение СДЭК. Получателю должно быть 18+, могут забрать родители.
А точно не скам?
Победители получат кружок в котором я назову их имя и расскажу о доставке приза.
С каналом Костыль разыгрываем 2 отличных приза:
Призы
Условия:
• подписаться на @Romancev768
• подписаться на @kostylofficial
• нажать на кнопку «Участвовать» под этим постом.
Двух победителей выберет рандомайзер.
Когда итоги?
В пятницу, 19 декабря, в 18:00
Где итоги?
В этом посте, вы его читаете, все итоги подводятся в постах с кнопкой «Участвовать».
Как получить?
Доставим в ближайшее отделение СДЭК. Получателю должно быть 18+, могут забрать родители.
А точно не скам?
Победители получат кружок в котором я назову их имя и расскажу о доставке приза.
Please open Telegram to view this post
VIEW IN TELEGRAM
const promise1 = Promise.resolve('first');
const promise2 = new Promise(resolve => {
resolve('second');
});
const promise3 = Promise.resolve().then(() => 'third');
async function test() {
console.log('start');
const result1 = await promise1;
console.log(result1);
const result2 = await promise2;
console.log(result2);
const result3 = await promise3;
console.log(result3);
console.log('end');
}
test();
Ответ:
JavaScript test | #JavaScript
Please open Telegram to view this post
VIEW IN TELEGRAM
const x = 5;
const y = 10;
const obj = {
x,
y,
z: x + y,
calculate() {
return this.x * this.y;
},
[x + y]: 'computed'
};
console.log(obj.calculate() + obj[15] + obj.z);
Ответ:
JavaScript test | #JavaScript
Please open Telegram to view this post
VIEW IN TELEGRAM
class Rectangle {
constructor(width, height) {
this.width = width;
this.height = height;
}
get area() {
return this.width * this.height;
}
}
const rectangle = new Rectangle(5, 10);
console.log(rectangle.area());
Ответ:
JavaScript test | #JavaScript
Please open Telegram to view this post
VIEW IN TELEGRAM
const curry = (fn) => {
return function curried(...args) {
if (args.length >= fn.length) {
return fn.apply(this, args);
}
return (...nextArgs) => curried(...args, ...nextArgs);
};
};
const multiply = (a, b, c) => a * b * c;
const curriedMultiply = curry(multiply);
const step1 = curriedMultiply(2);
const step2 = step1(3);
const result = step2(4);
console.log(result);
Ответ:
JavaScript test | #JavaScript
Please open Telegram to view this post
VIEW IN TELEGRAM