JavaScript test
10.6K subscribers
3.03K photos
6 videos
4.15K links
Проверка своих знаний по языку JavaScript.

Ссылка: @Portal_v_IT

Сотрудничество: @oleginc, @tatiana_inc

Канал на бирже: telega.in/c/js_test

РКН: clck.ru/3KHeYk
Download Telegram
❗️Что будет на выходе:

const obj = {
data: ['x', 'y', 'z'],
*[Symbol.iterator]() {
for (let i = this.data.length - 1; i >= 0; i--) {
yield this.data[i].toUpperCase();
}
}
};

const result = [];
for (const item of obj) {
result.push(item);
if (result.length === 2) break;
}

console.log(result.join('-'));

Ответ: Z-Y

JavaScript test | #JavaScript
❗️Что будет на выходе:

function outer() {
console.log(innerVar);
console.log(typeof innerFunc);

var innerVar = 42;

function innerFunc() {
return innerVar;
}

let anotherVar = 100;
console.log(typeof anotherVar);
}

outer();

Ответ: undefined 'function' 'number'

JavaScript test | #JavaScript
❗️Что будет на выходе:

console.log(MyClass);
class MyClass {
constructor() {
this.value = 42;
}
}

Ответ: Error

JavaScript test | #JavaScript
❗️Что будет на выходе:

const numbers = [1, 2, 3, 4, 5];

const sum = numbers.reduce((acc, curr) => {
setTimeout(() => {
acc += curr;
}, 0);
return acc;
}, 0);

console.log(sum);

Ответ: 0

JavaScript test | #JavaScript
❗️Что будет на выходе:

function Vehicle(wheels) {
this.wheels = wheels;
}

Vehicle.prototype.getWheels = function() {
return this.wheels;
};

function Car() {
Vehicle.call(this, 4);
this.doors = 4;
}

Car.prototype = Object.create(Vehicle.prototype);
Car.prototype.constructor = Car;

const myCar = new Car();
console.log(myCar.getWheels(), myCar instanceof Vehicle);

Ответ: 4 true

JavaScript test | #JavaScript
❗️Что будет на выходе:

const target = { name: 'Maya', age: 25 };
const handler = {
get(obj, prop) {
if (prop in obj) {
return obj[prop];
}
return `Property '${prop}' not found`;
},
set(obj, prop, value) {
if (typeof value === 'string') {
obj[prop] = value.toUpperCase();
} else {
obj[prop] = value;
}
return true;
}
};
const proxy = new Proxy(target, handler);
proxy.city = 'tokyo';
console.log(proxy.name);
console.log(proxy.city);
console.log(proxy.country);

Ответ: Maya TOKYO Property 'country' not found

JavaScript test | #JavaScript