function createCounter() {
let count = 0;
function increment() {
count++;
return count;
}
function decrement() {
count--;
return count;
}
return { increment, decrement, reset: () => count = 0 };
}
const counter = createCounter();
counter.increment();
counter.increment();
counter.decrement();
const { increment, reset } = counter;
increment();
reset();
increment();
console.log(counter.increment());
Ответ:
JavaScript test | #JavaScript
Please open Telegram to view this post
VIEW IN TELEGRAM
function greet(name) {
return `Hello, ${name}!`;
}
function highlight(strings, ...values) {
return strings.reduce((result, str, i) => {
return result + str + (values[i] ? `<em>${values[i]}</em>` : '');
}, '');
}
const user = 'Sarah';
const status = 'online';
console.log(highlight`User ${user} is currently ${status}.`);
Ответ:
JavaScript test | #JavaScript
Please open Telegram to view this post
VIEW IN TELEGRAM
function createCounter() {
let count = 0;
return {
increment() {
count++;
return count;
},
getCount() {
return count;
}
};
}
const counter = createCounter();
console.log(counter.increment());
console.log(counter.getCount());
console.log(counter.increment());
console.log(counter.getCount());
Ответ:
Please open Telegram to view this post
VIEW IN TELEGRAM
const sym1 = Symbol('test');
const sym2 = Symbol('test');
const obj = {
[sym1]: 'first',
[sym2]: 'second',
regular: 'third'
};
const keys = Object.keys(obj);
const symbols = Object.getOwnPropertySymbols(obj);
const allProps = Reflect.ownKeys(obj);
console.log(keys.length);
console.log(symbols.length);
console.log(allProps.length);
console.log(sym1 === sym2);
Ответ:
Please open Telegram to view this post
VIEW IN TELEGRAM
var a = 0, b = 0, arr = [3, 6, 9, 6, 9, 3];
var data = arr.some((x, i)=>{
a = arr[i];
b = arr[i + 1];
return a + b == 15
})
console.log(data)
console.log(a, b)
Ответ:
6 9
JavaScript test | #JavaScript
Please open Telegram to view this post
VIEW IN TELEGRAM
function createCounter() {
let count = 0;
return {
increment: () => ++count,
decrement: () => --count,
get: () => count
};
}
const counter1 = createCounter();
const counter2 = createCounter();
counter1.increment();
counter1.increment();
counter2.increment();
console.log(counter1.get(), counter2.get());
const { increment, get } = counter1;
increment();
console.log(get());Ответ:
2 1 3
JavaScript test | #JavaScript
Please open Telegram to view this post
VIEW IN TELEGRAM
let a = 1;
setTimeout(() => {
a = 2;
}, 0);
console.log(a);
Ответ:
Please open Telegram to view this post
VIEW IN TELEGRAM
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