const Flyable = {
fly() { return 'flying'; }
};
const Swimmable = {
swim() { return 'swimming'; }
};
function applyMixins(target, ...mixins) {
mixins.forEach(mixin => {
Object.assign(target.prototype, mixin);
});
}
class Bird {}
class Fish {}
applyMixins(Bird, Flyable, Swimmable);
applyMixins(Fish, Swimmable);
const eagle = new Bird();
const shark = new Fish();
console.log(eagle.swim());
console.log(shark.fly?.() || 'undefined method');
Ответ:
Please open Telegram to view this post
VIEW IN TELEGRAM
console.log('1');
setTimeout(() => console.log('2'), 0);
Promise.resolve().then(() => console.log('3'));
setTimeout(() => console.log('4'), 0);
console.log('5');
Promise.resolve().then(() => {
console.log('6');
return Promise.resolve();
}).then(() => console.log('7'));
queueMicrotask(() => console.log('8'));
console.log('9');
Ответ:
JavaScript test | #JavaScript
Please open Telegram to view this post
VIEW IN TELEGRAM
const data = [1, 2, 3, 4, 5];
const result = data.reduce((acc, val) => acc.concat(Array.from({ length: val }, (_, index) => val + index)), []);
console.log(result);
Ответ:
JavaScript test | #JavaScript
Please open Telegram to view this post
VIEW IN TELEGRAM
const user = {
name: 'John',
age: 35,
};
for (const value in user) {
console.log(value);
}
Ответ:
age
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
let x = 5;
function foo() {
console.log(x);
let x = 10;
console.log(x);
}
foo();
Ответ:
Please open Telegram to view this post
VIEW IN TELEGRAM
Вакансии только с прямыми контактами в Telegram! Ноль автоотказов — живой диалог и быстрые объективные решения.
🤖 ML & DS
🔎 QA 👨✈️ CyberSec
💼 1C
👩💻 IT HR
Подпишись чтобы не упустить свой шанс получить лучший оффер!
Please open Telegram to view this post
VIEW IN TELEGRAM
let obj = { name: 'Sarah', age: 25 };
let weakMap = new WeakMap();
let map = new Map();
weakMap.set(obj, 'weak reference');
map.set(obj, 'strong reference');
console.log(weakMap.has(obj));
console.log(map.has(obj));
obj = null;
console.log(weakMap.has(null));
console.log(map.has(null));
console.log(map.size);
Ответ:
Please open Telegram to view this post
VIEW IN TELEGRAM
const weakMap = new WeakMap();
const objs = [{}, {}, {}];
objs.forEach((obj, index) => weakMap.set(obj, index + 1));
const result = objs.filter(obj => weakMap.has(obj)).map(obj => weakMap.get(obj) * 2);
console.log(result);
Ответ:
Please open Telegram to view this post
VIEW IN TELEGRAM
const target = { name: 'Sarah', age: 25 };
const handler = {
get(obj, prop) {
if (prop === 'toString') {
return () => `Person: ${obj.name}`;
}
return Reflect.get(obj, prop);
},
has(obj, prop) {
return prop !== 'age' && Reflect.has(obj, prop);
}
};
const proxy = new Proxy(target, handler);
console.log(proxy.name);
console.log('age' in proxy);
console.log(proxy.toString());
Ответ:
JavaScript test | #JavaScript
Please open Telegram to view this post
VIEW IN TELEGRAM
Telegram
JavaScript test
Проверка своих знаний по языку JavaScript.
Ссылка: @Portal_v_IT
Сотрудничество: @oleginc, @tatiana_inc
Канал на бирже: telega.in/c/js_test
РКН: clck.ru/3KHeYk
Ссылка: @Portal_v_IT
Сотрудничество: @oleginc, @tatiana_inc
Канал на бирже: telega.in/c/js_test
РКН: clck.ru/3KHeYk
Мы тут ChatGPT с Midjoney обьединили и в телеграм интегрировали!
Бот подключен сразу к двум нейросетям и буквально за секунду сгенерирует любой ваш запрос. Вы найдете его в закрепе канала
Самое вкусное в закрепе - Нейрофлоу | VEO 3.1 | ChatGPT 5
Бот подключен сразу к двум нейросетям и буквально за секунду сгенерирует любой ваш запрос. Вы найдете его в закрепе канала
Нейрофлоу | VEO 3.1 | ChatGPT 5, где ежедневно публикуются обновления и новости связанные с нейросетямиСамое вкусное в закрепе - Нейрофлоу | VEO 3.1 | ChatGPT 5
const obj = {};
obj.length = 5;
console.log(obj.length);
JavaScript test | #JavaScript
Please open Telegram to view this post
VIEW IN TELEGRAM
const array = [1, 2, 3, 4];
const result = array.reduceRight((acc, val) => acc - val);
console.log(result);
Ответ:
Please open Telegram to view this post
VIEW IN TELEGRAM
function createCounter() {
let count = 0;
return {
increment() {
return ++count;
},
reset() {
const oldCount = count;
count = 0;
return oldCount;
}
};
}
const counterA = createCounter();
const counterB = createCounter();
counterA.increment();
counterA.increment();
counterB.increment();
const result = counterA.reset() + counterB.reset();
console.log(result);
Ответ:
Please open Telegram to view this post
VIEW IN TELEGRAM
const user = {
profile: {
settings: {
theme: 'dark',
notifications: null
}
}
};
const result1 = user?.profile?.settings?.theme;
const result2 = user?.profile?.settings?.notifications?.email;
const result3 = user?.profile?.preferences?.language ?? 'en';
const result4 = user?.profile?.settings?.notifications?.push?.('test');
console.log(result1, result2, result3, result4);
Ответ:
JavaScript test | #JavaScript
Please open Telegram to view this post
VIEW IN TELEGRAM
const original = {
name: 'Sarah',
hobbies: ['reading', 'coding'],
address: { city: 'Portland', zip: 97201 }
};
const shallow = { ...original };
const deep = JSON.parse(JSON.stringify(original));
shallow.name = 'Emma';
shallow.hobbies.push('hiking');
shallow.address.city = 'Seattle';
deep.hobbies.push('swimming');
deep.address.zip = 98101;
console.log(original.hobbies.length, original.address.city);
Ответ:
JavaScript test | #JavaScript
Please open Telegram to view this post
VIEW IN TELEGRAM
var str="My name is John";
var words1=str.split(" ",3);
console.log("words1:",words1);
var words2=str.split(" ",5);
console.log("words2:",words2);
Ответ:
words1:[ 'My', 'name', 'is' ]
words2:[ 'My', 'name', 'is', 'John' ]
JavaScript test | #JavaScript
Please open Telegram to view this post
VIEW IN TELEGRAM
class SimpleObservable {
constructor(subscribeFn) {
this.subscribeFn = subscribeFn;
}
subscribe(observer) {
return this.subscribeFn(observer);
}
}
const obs = new SimpleObservable(observer => {
observer.next('first');
observer.next('second');
observer.complete();
});
const results = [];
obs.subscribe({
next: val => results.push(val),
complete: () => results.push('done')
});
console.log(results.join('-'));
Ответ:
JavaScript test | #JavaScript
Please open Telegram to view this post
VIEW IN TELEGRAM
❗️Что будет на выходе:
Ответ:Script Start, Async Start, Script End, Timeout 1, Async End, Timeout 2
JavaScript test | #JavaScript
async function asyncFunc() {
console.log('Async Start');
await new Promise(resolve => setTimeout(resolve, 100));
console.log('Async End');
}
console.log('Script Start');
asyncFunc();
setTimeout(() => console.log('Timeout 1'), 50);
setTimeout(() => console.log('Timeout 2'), 150);
console.log('Script End');
Ответ:
const numbers = [1, 2, 3, 4, 5];
const result = numbers
.map(n => n * 2)
.filter(n => n > 5)
.reduce((acc, n, index) => {
acc.sum += n;
acc.indices.push(index);
return acc;
}, { sum: 0, indices: [] });
console.log(result.sum);
console.log(result.indices);
Ответ:
JavaScript test | #JavaScript
Please open Telegram to view this post
VIEW IN TELEGRAM