❗️Что будет на выходе:
Ответ:Start, Outside, Inside, Promise, End
JavaScript test | #JavaScript
async function foo() {
console.log('Start');
await Promise.resolve().then(() => {
console.log('Inside Promise');
});
console.log('End');
}
foo();
console.log('Outside');Ответ:
❗️Что будет на выходе:
Ответ:DB: Saving user user_saved
JavaScript test | #JavaScript
class Logger {
constructor(prefix) {
this.prefix = prefix;
}
log(message) {
console.log(`${this.prefix}: ${message}`);
}
}
class Database {
constructor(logger) {
this.logger = logger;
}
save(data) {
this.logger.log(`Saving ${data}`);
return `${data}_saved`;
}
}
const logger = new Logger('DB');
const db = new Database(logger);
const result = db.save('user');
console.log(result);Ответ:
❗️Что будет на выходе:
Ответ:4
JavaScript test | #JavaScript
const str = "a 1 b 2 c 3 d 04";
function foo(str) {
const regex = /\d+/g;
const matches = str.match(regex);
return matches.lenght;
}
Ответ:
JavaScript test | #JavaScript
const obj = { a: 1, b: 2 };
const proxy = new Proxy(obj, {
get(target, prop) {
return prop in target ? target[prop] : 0;
}
});
console.log(proxy.a, proxy.b, proxy.c);Ответ:
JavaScript test | #JavaScript
Please open Telegram to view this post
VIEW IN TELEGRAM
const target = { name: 'Sarah', age: 25 };
const handler = {
get(obj, prop) {
if (prop in obj) {
return obj[prop];
}
return `Property '${prop}' not found`;
},
set(obj, prop, value) {
obj[prop] = value.toString().toUpperCase();
return true;
}
};
const proxy = new Proxy(target, handler);
proxy.city = 'boston';
console.log(proxy.name);
console.log(proxy.city);
console.log(proxy.country);Ответ:
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
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
var a=[1,2,3,4,5];
a.every(x=>{
console.log(x);
return x<4;
})
Ответ:
1
2
3
4
JavaScript test | #JavaScript
Please open Telegram to view this post
VIEW IN TELEGRAM
const numbers = [1, 2, 3];
numbers.push(4);
console.log(numbers);
Ответ:
Please open Telegram to view this post
VIEW IN TELEGRAM
class Counter {
constructor(max) {
this.max = max;
}
*[Symbol.iterator]() {
let current = 0;
while (current < this.max) {
yield current++;
}
}
}
const counter = new Counter(3);
const result = [...counter, ...counter];
console.log(result);Ответ:
Please open Telegram to view this post
VIEW IN TELEGRAM
const x = [1, 2, 3, 4, 5];
console.log(x.slice(1, 3));
Ответ:
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 weakMap = new WeakMap();
const array = [{}, {}];
array.forEach(obj => weakMap.set(obj, obj));
const result = array.map(obj => weakMap.get(obj) === obj);
console.log(result);
Ответ:
Please open Telegram to view this post
VIEW IN TELEGRAM
const arr = Array.from({ length: 3 }, (_, i) => i * 2);
for (const i of arr) {
console.log(i);
} Ответ:
JavaScript test | #JavaScript
Please open Telegram to view this post
VIEW IN TELEGRAM
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
const array = Array.from({ length: 5 }, () => Math.random() > 0.5);
console.log(array);Ответ:
JavaScript test | #JavaScript
Please open Telegram to view this post
VIEW IN TELEGRAM
const array = [1, 2, 3, 4, 5];
const [first, ...rest] = array;
const modified = rest.map((n, i) => i % 2 === 0 ? n * 2 : n);
console.log(first, modified);
Ответ:
JavaScript test | #JavaScript
Please open Telegram to view this post
VIEW IN TELEGRAM
function processData(data) {
try {
if (!data) {
throw new TypeError('Data is missing');
}
const result = data.process();
return result;
} catch (error) {
console.log(error instanceof ReferenceError ? 1 :
error instanceof TypeError ? 2 :
error instanceof SyntaxError ? 3 : 4);
}
}
processData(null);Ответ:
JavaScript test | #JavaScript
Please open Telegram to view this post
VIEW IN TELEGRAM
const add = x => y => x + y;
const multiply = x => y => x * y;
const subtract = x => y => x - y;
const result = add(10)(multiply(2)(subtract(5)(3)));
console.log(result);
Ответ:
JavaScript test | #JavaScript
Please open Telegram to view this post
VIEW IN TELEGRAM
setTimeout(() => {
console.log('setTimeout 1');
Promise.resolve().then(() => console.log('Promise 1'));
}, 0);
Promise.resolve().then(() => {
console.log('Promise 2');
setTimeout(() => console.log('setTimeout 2'), 0);
});
console.log('Sync');Ответ:
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