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

Ссылка: @Portal_v_IT

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

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

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

function calc(num) {
return num + 0.01 * '0';
}

typeof calc('hello');

Ответ: 'string'

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

function Animal(name) {
this.name = name;
}

Animal.prototype.getName = function() {
return this.name;
};

function Dog(name, breed) {
Animal.call(this, name);
this.breed = breed;
}

Dog.prototype = Object.create(Animal.prototype);
Dog.prototype.constructor = Dog;

Dog.prototype.getName = function() {
return `Dog called ${Animal.prototype.getName.call(this)}`;
};

const myDog = new Dog('Rex', 'German Shepherd');
console.log(myDog.getName());

Ответ: Dog called Rex

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

function asyncQuiz() {
return new Promise((resolve) => {
setTimeout(() => resolve('World'), 100);
});
}

async function runAsyncQuiz() {
const result = await asyncQuiz();
console.log(result);
}

console.log('World');
runAsyncQuiz();

Ответ: 'World'
'World'


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

async function asyncArrayOperations() {
const array1 = [1, 2, 3];
const array2 = [4, 5, 6];
const array3 = [7, 8, 9];

const result = await Promise.all([array1, array2, array3].map(async arr => {
return await arr.filter(async (acc, num) => {
return (await acc) + num;
}, Promise.resolve(0));
}));

console.log(result);
}

asyncArrayOperations();

Ответ: [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]

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

console.log(new RegExp({}).test("test"));
console.log(new RegExp({}).test("why?"));
console.log(new RegExp({}).test("cause"));

Ответ: true
false
true


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

const obj = {
value: 42,
getValue() {
return this.value;
},
getValueArrow: () => this.value,
nested: {
value: 100,
getValue() {
return this.value;
}
}
};

const extractedMethod = obj.getValue;
const boundMethod = obj.getValue.bind(obj);

console.log(obj.getValue() + ',' + obj.getValueArrow() + ',' +
obj.nested.getValue() + ',' + extractedMethod() + ',' +
boundMethod());

Ответ: 42, undefined, 100, undefined, 42

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

const target = { a: 1, b: 2 };
const handler = {
get(obj, prop) {
return prop === 'sum' ? obj.a + obj.b : Reflect.get(obj, prop);
},
set(obj, prop, value) {
if (prop === 'a' && value < 0) {
return false;
}
return Reflect.set(obj, prop, value);
}
};

const proxy = new Proxy(target, handler);
proxy.a = -5;
proxy.b = 10;
console.log(`${proxy.a}, ${proxy.b}, ${proxy.sum}`);

Ответ: 1, 10, 11

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

const string = "Hello, World!";

const result = [...string.matchAll(/[HlWrd]/g)]
.map(match => match[0])
.reverse()
.join("");

console.log(result);

Ответ: 'dlrWllH'

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

const obj = {
value: 10,
getValue() {
return this.value;
},
getArrowValue: () => {
return this.value;
},
getMixedValue() {
const regular = function() { return this.value; };
const arrow = () => this.value;

return [regular(), arrow()];
}
};

console.log(obj.getMixedValue());

Ответ: [undefined, 10]

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

function recursiveReverseString(str) {
return str === "" ? str : recursiveReverseString(str.substr(1)) + str;
}

const result = recursiveReverseString("hello");

console.log(result);

Ответ: 'ololloellohello'

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

const sym = Symbol('unique');
const obj = {
[sym]: 'symbol value',
a: 0,
b: 2,
c: 1
};

const keys = Object.keys(obj);
const symbols = Object.getOwnPropertySymbols(obj);

console.log(keys.length, symbols.length);

Ответ: 3 1

JavaScript test | #JavaScript
Forwarded from DevHumor
This media is not supported in your browser
VIEW IN TELEGRAM
Вечерний мем

Взято из: DevHumor
❗️Что будет на выходе?

const obj = {
value: 42,
getValue() {
return this.value;
},
getArrowValue: () => {
return this.value;
},
getDelayedValue() {
setTimeout(function() {
console.log(this.value);
}, 0);
},
getFixedDelayedValue() {
setTimeout(() => {
console.log(this.value);
}, 0);
}
};

obj.getDelayedValue();

Ответ: undefined

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

const arr = [1, 2, 3];
const str = arr.join([4]);
console.log(typeof str);
console.log(str);

Ответ: 'string'
'14243'


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

const target = { name: 'Alice' };

const handler = {
get(obj, prop) {
return prop in obj ? obj[prop].toUpperCase() : 'NOT_FOUND';
},
set(obj, prop, value) {
if (typeof value !== 'string') {
return false;
}
obj[prop] = value.trim();
return true;
}
};

const proxy = new Proxy(target, handler);
proxy.name = ' Bob ';
proxy.age = 30;

console.log(`${proxy.name}-${proxy.age}-${proxy.job}`);

Ответ: BOB-NOT_FOUND-NOT_FOUND

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

var b = 10;
let i = 7;
if (b % 3 == 0) {
let i = 10;
}

console.log(i);

Ответ: 7

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

const inventory = {
items: ['apple', 'banana', 'orange'],
[Symbol.iterator]: function() {
let index = 0;
const items = this.items;

return {
next: function() {
return index < items.length ?
{ value: items[index++].toUpperCase(), done: false } :
{ done: true };
}
};
}
};

const result = [...inventory].join(' + ');
console.log(result);

Ответ: APPLE + BANANA + ORANGE

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

async function asyncChain() {
const values = [2, 3, 5, 7, 11];
const total = await values.reduce(async (acc, values) => {
const current = await acc;
return current * value;
}, Promise.resolve(1));
return total;
}

asyncChain().then(result => console.log(result));

Ответ: 2310

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

console.log(console.log(0 || {a: 3} && 1 || ['hello'] * 2 + 5));

Ответ: 1
undefined


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

const obj = {};
const sym1 = Symbol('description');
const sym2 = Symbol('description');

obj[sym1] = 'Value 1';
obj[sym2] = 'Value 2';
obj.regularProp = 'Regular';

const allKeys = Object.getOwnPropertySymbols(obj).length + Object.keys(obj).length;
const comparison = sym1 === sym2;

console.log(allKeys + ',' + comparison);

Ответ: 3, false

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

const weakMap = new WeakMap();
const obj1 = {};
const obj2 = {};

weakMap.set(obj1, 'value1');
weakMap.set(obj2, 'value2');

const arr = [obj1, obj2];
const result = arr.map(obj => weakMap.get(obj)).join(', ');

console.log(result);

Ответ: "value1, value2"

JavaScript test | #JavaScript