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

Ссылка: @Portal_v_IT

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

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

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

setTimeout(() => {
console.log(2);
}, 100);

setTimeout(() => {
console.log(3);
}, 0);

Promise.resolve().then(() => {
console.log(4);
}).then(() => {
console.log(5);
});

console.log(6);


Ответ: 1, 6, 4, 5, 3, 2

JavaScript test | #JavaScript
Please open Telegram to view this post
VIEW IN TELEGRAM
❗️Что будет на выходе:
console.log('1');

setTimeout(() => console.log('2'), 0);

Promise.resolve().then(() => console.log('3'));

queueMicrotask(() => console.log('4'));

setTimeout(() => console.log('5'), 0);

Promise.resolve().then(() => {
console.log('6');
return Promise.resolve();
}).then(() => console.log('7'));

console.log('8');


Ответ: 1 8 3 4 6 7 2 5

JavaScript test | #JavaScript
Please open Telegram to view this post
VIEW IN TELEGRAM
❗️Что будет на выходе:

console.log('Start');

setTimeout(() => console.log('Timeout 1'), 0);

setTimeout(() => console.log('Timeout 2'), 0);

console.log('End');


Ответ: "Start" "End" "Timeout 1" "Timeout 2"

JavaScript test | #JavaScript
Please open Telegram to view this post
VIEW IN TELEGRAM
❗️Что будет на выходе:
const secret = 'hidden';
function revealSecret() {
const secret = 'revealed';
const obj = { secret: 'object secret' };
with (obj) {
return () => secret;
}
}

const mySecret = revealSecret()();
console.log(mySecret);


Ответ: object secret

JavaScript test | #JavaScript
Please open Telegram to view this post
VIEW IN TELEGRAM
❗️Что будет на выходе:
class CustomError extends Error {
constructor(message) {
super(message);
this.name = 'CustomError';
}
}

try {
try {
throw new CustomError('inner error');
} catch (e) {
console.log(e.name);
throw new Error('outer error');
}
} catch (e) {
console.log(e.message);
console.log(e instanceof CustomError);
}


Ответ: CustomError outer false

JavaScript test | #JavaScript
Please open Telegram to view this post
VIEW IN TELEGRAM
❗️Что будет на выходе:
const original = {
name: 'Sarah',
scores: [85, 92, 78],
details: {
age: 25,
city: 'Portland'
}
};

const copy1 = { ...original };
const copy2 = JSON.parse(JSON.stringify(original));

copy1.name = 'Emma';
copy1.scores.push(95);
copy1.details.age = 30;

console.log(original.name, original.scores.length, original.details.age);


Ответ: Sarah 4 30

JavaScript test | #JavaScript
Please open Telegram to view this post
VIEW IN TELEGRAM
❗️Что будет на выходе:
function Animal() {}

function Dog() {}

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

const rover = new Dog();

console.log(rover.constructor === Animal);


Ответ: true

JavaScript test | #JavaScript
Please open Telegram to view this post
VIEW IN TELEGRAM
❗️Что будет на выходе:

const clothes = [ 'jacket', 't-shirt' ];
clothes.length = 0;
console.log(clothes[0]);


Ответ: undefined

JavaScript test | #JavaScript
Please open Telegram to view this post
VIEW IN TELEGRAM
❗️Что будет на выходе:

const obj = {};
obj.length = 5;
console.log(obj.length);


JavaScript test | #JavaScript
Please open Telegram to view this post
VIEW IN TELEGRAM
❗️Что будет на выходе:

console.log(typeof typeof undefined);


Ответ: "string"

JavaScript test | #JavaScript
Please open Telegram to view this post
VIEW IN TELEGRAM
❗️Что будет на выходе:

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
Please open Telegram to view this post
VIEW IN TELEGRAM
❗️Что будет на выходе:

function createCounter() {
let count = 0;
return {
increment: () => ++count,
decrement: () => --count,
getValue: () => count
};
}

const counter1 = createCounter();
const counter2 = createCounter();
counter1.increment();
counter1.increment();
counter2.increment();
console.log(counter1.getValue() + counter2.getValue());


Ответ: 3

JavaScript test | #JavaScript
Please open Telegram to view this post
VIEW IN TELEGRAM
❗️Что будет на выходе:

const original = {
name: 'Emma',
skills: ['JavaScript', 'Python'],
config: { theme: 'dark', notifications: true }
};

const copy1 = { ...original };
const copy2 = JSON.parse(JSON.stringify(original));
const copy3 = Object.assign({}, original);

copy1.name = 'Sarah';
copy1.skills.push('React');
copy1.config.theme = 'light';

console.log(original.name);
console.log(original.skills.length);
console.log(original.config.theme);


Ответ: Emma, 3, light

JavaScript test | #JavaScript
Please open Telegram to view this post
VIEW IN TELEGRAM
❗️Что будет на выходе:

const obj = { a: 1, b: 2, c: 3 };
const result = Object.values(obj).reduce((acc, curr) => acc * curr, 1);
console.log(result);


Ответ: 6

JavaScript test | #JavaScript
Please open Telegram to view this post
VIEW IN TELEGRAM
❗️Что будет на выходе:

const obj = {
name: 'Sarah',
regularMethod: function() {
return () => {
console.log(this.name);
};
},
arrowMethod: () => {
return () => {
console.log(this.name);
};
}
};

const regular = obj.regularMethod();
const arrow = obj.arrowMethod();
regular();
arrow();


Ответ: Sarah, undefined

JavaScript test | #JavaScript
Please open Telegram to view this post
VIEW IN TELEGRAM
❗️Что будет на выходе:


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


Ответ: Error

JavaScript test | #JavaScript
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');


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

JavaScript test | #JavaScript
Please open Telegram to view this post
VIEW IN TELEGRAM
❗️Что будет на выходе:

class EventManager {
constructor() {
this.listeners = new Map();
}

addListener(event, callback) {
if (!this.listeners.has(event)) {
this.listeners.set(event, new Set());
}
this.listeners.get(event).add(callback);
}
}

const manager = new EventManager();
const obj = { name: 'Component' };
manager.addListener('click', () => console.log(obj.name));
obj = null;
console.log(manager.listeners.get('click').size);


Ответ: TypeError: Assignment to constant variable

JavaScript test | #JavaScript
Please open Telegram to view this post
VIEW IN TELEGRAM
❗️Что будет на выходе:



const step1 = multiply(2);
const step2 = step1(3);
const result1 = step2(4);

const result2 = multiply(2)(3)(4);

const partialMultiply = multiply(5);
const result3 = partialMultiply(2)(3);

const doubler = multiply(2)(1);
const result4 = doubler(7);

console.log(result1, result2, result3, result4);


Ответ: 24, 24, 30, 14

JavaScript test | #JavaScript
Please open Telegram to view this post
VIEW IN TELEGRAM