❗️Что будет на выходе:
Ответ:undefined 'function' 'number'
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();
Ответ:
JavaScript test | #JavaScript
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
❗️Что будет на выходе:
Ответ:Error
JavaScript test | #JavaScript
console.log(MyClass);
class MyClass {
constructor() {
this.value = 42;
}
}
Ответ:
❗️Что будет на выходе:
Ответ:0
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);
Ответ:
JavaScript test | #JavaScript
❗️Что будет на выходе:
Ответ:4 true
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);
Ответ:
JavaScript test | #JavaScript
❗️Что будет на выходе:
Ответ:Maya TOKYO Property 'country' not found
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);
Ответ:
❗️Что будет на выходе:
Ответ:developer true undefined error
JavaScript test | #JavaScript
const wm = new WeakMap();
let obj1 = { name: 'John' };
let obj2 = { name: 'Jane' };
wm.set(obj1, 'developer');
wm.set(obj2, 'designer');
console.log(wm.get(obj1));
console.log(wm.has(obj2));
obj1 = null;
console.log(wm.get(obj1));
const normalObj = {};
try {
wm.set('string', 'value');
} catch (e) {
console.log('error');
}
Ответ:
❗️Что будет на выходе:
Ответ:1 5 9 3 6 8 7 2 4
JavaScript test | #JavaScript
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
❗️Что будет на выходе:
Ответ:18 [0, 1, 2]
JavaScript test | #JavaScript
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
❗️Что будет на выходе:
Ответ:This is a car made by Tesla car
JavaScript test | #JavaScript
function Vehicle(type) {
this.type = type;
}
Vehicle.prototype.describe = function() {
return `This is a ${this.type}`;
};
function Car(brand) {
Vehicle.call(this, 'car');
this.brand = brand;
}
Car.prototype = Object.create(Vehicle.prototype);
Car.prototype.constructor = Car;
Car.prototype.describe = function() {
return Vehicle.prototype.describe.call(this) + ` made by ${this.brand}`;
};
const tesla = new Car('Tesla');
console.log(tesla.describe());
console.log(tesla.constructor.name);
Ответ:
JavaScript test | #JavaScript
❗️Что будет на выходе:
Ответ:1, user-1
JavaScript test | #JavaScript
const cache = new Map();
function createHandler(id) {
const data = { id, value: new Array(1000).fill(id) };
cache.set(id, data);
return function(action) {
if (action === 'get') return data;
if (action === 'clear') cache.delete(id);
};
}
const handler1 = createHandler('user-1');
const handler2 = createHandler('user-2');
handler1('clear');
console.log(cache.size);
console.log(handler1('get').id);
Ответ:
JavaScript test | #JavaScript
❗️Что будет на выходе:
Ответ:2 6 2
JavaScript test | #JavaScript
const nums = [1, 2, 3];
const obj = { a: 1, b: 2 };
const newObj = { ...obj, b: 3, ...obj };
const arr1 = [4, 5];
const arr2 = [6, 7];
const combined = [...nums, ...arr1, ...arr2];
const [first, ...rest] = combined;
const { a, ...remaining } = newObj;
console.log(newObj.b);
console.log(rest.length);
console.log(remaining.b);
Ответ:
JavaScript test | #JavaScript
❗️Что будет на выходе:
Ответ:["123", "456", "789"]
JavaScript test | #JavaScript
const string = "“abc123def456ghi789";
const matches =
string.match(/\d+/g);
console. log(matches );
Ответ:
JavaScript test | #JavaScript