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
var foo = {};
var bar = Object.create(foo);
foo.a = 1;
console.log(bar.a);
Ответ:
JavaScript test | #JavaScript
Please open Telegram to view this post
VIEW IN TELEGRAM
const a = { x: 1 };
const b = a;
const c = { x: 1 };
b.x = 2;
const d = b;
d.x = 3;
console.log(a.x);
console.log(b.x);
console.log(c.x);
console.log(a === b);
console.log(a === c);
Ответ:
JavaScript test | #JavaScript
Please open Telegram to view this post
VIEW IN TELEGRAM
function processConfig(config) {
const settings = {
timeout: config.timeout ?? 1000,
retries: config.retries ?? 3,
logging: config.logging ?? false,
debug: config.debug || true
};
return settings;
}
const userConfig = {
timeout: 0,
retries: null,
logging: false,
debug: false
};
console.log(processConfig(userConfig));
Ответ:
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 str1 = 'Hi\nthere';
const str2 = 'Hi
there';
str1 === str2;
Ответ:
JavaScript test | #JavaScript
Please open Telegram to view this post
VIEW IN TELEGRAM
var a = 5;
function test() {
console.log(a);
var a = 10;
console.log(a);
}
test();
Ответ:
Please open Telegram to view this post
VIEW IN TELEGRAM
class Subject {
constructor() {
this.observers = [];
}
attach(observer) {
this.observers.push(observer);
}
notify(data) {
this.observers.forEach(obs => obs.update(data));
}
}
const subject = new Subject();
subject.attach({ update: (d) => console.log(d * 2) });
subject.attach({ update: (d) => console.log(d + 5) });
subject.notify(10);
Ответ:
JavaScript test | #JavaScript
Please open Telegram to view this post
VIEW IN TELEGRAM
const obj = { a: 1, b: 2, c: 3 };
Object.defineProperty(obj, 'd', {
value: 4,
enumerable: false
});
const entries = Object.entries(obj);
const keys = Object.keys(obj);
const values = Object.values(obj);
console.log(entries.length + keys.length + values.length);
Ответ:
JavaScript test | #JavaScript
Please open Telegram to view this post
VIEW IN TELEGRAM
console.log(1);
setTimeout(() => {
console.log(2);
}, 100);
setTimeout(() => {
console.log(3);
}, 0);
Promise.resolve().then(() => {
console.log(4);
}).then(() => {
console.log(5);
});
console.log(6);
Ответ:
JavaScript test | #JavaScript
Please open Telegram to view this post
VIEW IN TELEGRAM