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
❗️Что будет на выходе:
let a = 1;
let b = new Number(1);
let c = '1';

console.log(a == b);
console.log(a === b);
console.log(b == c);

Ответ: true false true

JavaScript test | #JavaScript
Please open Telegram to view this post
VIEW IN TELEGRAM
❗️Что будет на выходе:
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
Please open Telegram to view this post
VIEW IN TELEGRAM
❗️Что будет на выходе:
const a = [1, 2, 3, 4];
console.log(a + "");


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

JavaScript test | #JavaScript
Please open Telegram to view this post
VIEW IN TELEGRAM
❗️Что будет на выходе:
const numbers = [1, 2, 3, 4, 5];

const result = numbers
.map(x => x * 2)
.filter(x => x > 5)
.reduce((acc, x) => {
acc.push(x.toString());
return acc;
}, [])
.map(x => x + '!')
.join(' | ');

console.log(result);
console.log(typeof result);


Ответ: 6! | 8! | 10! string

JavaScript test | #JavaScript
Please open Telegram to view this post
VIEW IN TELEGRAM
❗️Что будет на выходе:
var a = 5;
function test() {
console.log(a);
var a = 10;
console.log(a);
}

test();

Ответ: undefined 10

JavaScript test | #JavaScript
Please open Telegram to view this post
VIEW IN TELEGRAM
❗️Что будет на выходе:
function createCounter() {
let count = 0;
return {
increment() {
count++;
return count;
},
getCount() {
return count;
}
};
}

const counter = createCounter();

console.log(counter.increment());
console.log(counter.getCount());
console.log(counter.increment());
console.log(counter.getCount());

Ответ: 1, 1, 2, 2

JavaScript test | #JavaScript
Please open Telegram to view this post
VIEW IN TELEGRAM
🚀 С 25 по 29 августа пройдёт Podlodka React Crew #3 — сезон о паттернах и практиках фронтенда.

В программе:

💡 Паттерны и подводные камни View Transition API в React (Николай Шабалин, СберЗдоровье)

🧠 Глубокое погружение в архитектуру React Hooks (Максим Никитин, Rocket Science)

⚙️ Разбор FSD 2.1 на практике, без догм (Лев Челядинов, FSD Core team)

📚Подготовка к архитектурному интервью для фронтендеров (Игорь Антонов, Т-Банк)

📐Layout-паттерны за пределами Flexbox и CSS Grid (Саша Илатовский, Albato)

🎯 Все темы прикладные, с практикой и кейсами.

🔗 Подробности и билеты

P.S: Для подписчиков группы JavaScript Test скидка 500 р по промокоду react_crew_3_6oJaWL
❗️Что будет на выходе:
console.log(false || 1 + true || 2);

Ответ: 2

JavaScript test | #JavaScript
Please open Telegram to view this post
VIEW IN TELEGRAM
❗️Что будет на выходе:
const sym1 = Symbol('test');
const sym2 = Symbol('test');
const obj = {
[sym1]: 'first',
[sym2]: 'second',
regular: 'third'
};

const keys = Object.keys(obj);
const symbols = Object.getOwnPropertySymbols(obj);
const allProps = Reflect.ownKeys(obj);

console.log(keys.length);
console.log(symbols.length);
console.log(allProps.length);
console.log(sym1 === sym2);

Ответ: 1 2 3 false

JavaScript test | #JavaScript
Please open Telegram to view this post
VIEW IN TELEGRAM
❗️Что будет на выходе:
var obj = {
a: 10,
b: 20,
c: 'hello'
};

with (obj) {
var sum = a + b;
var greeting = c + ' world';
}

console.log(sum, greeting);


Ответ: 30, 'undefined'

JavaScript test | #JavaScript
Please open Telegram to view this post
VIEW IN TELEGRAM
❗️Что будет на выходе:
const values = [null, undefined, '', 0, false, NaN];
const results = [];

for (let val of values) {
results.push({
value: val,
boolean: !!val,
string: String(val),
number: Number(val)
});
}

console.log(results[2].boolean);
console.log(results[3].string);
console.log(results[1].number);


Ответ: false 0 NaN

JavaScript test | #JavaScript
Please open Telegram to view this post
VIEW IN TELEGRAM
❗️Что будет на выходе:
function a() {
console.log(arguments[0]);
}

a([1]);


Ответ: [1]

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);


Ответ: An array of 5 random true/false values

JavaScript test | #JavaScript
Please open Telegram to view this post
VIEW IN TELEGRAM
❗️Что будет на выходе:
class StateMachine {
constructor() {
this.state = 'idle';
this.transitions = {
idle: { start: 'running' },
running: { pause: 'paused', stop: 'stopped' },
paused: { resume: 'running', stop: 'stopped' },
stopped: { reset: 'idle' }
};
}

transition(action) {
const next = this.transitions[this.state]?.[action];
if (next) this.state = next;
return this.state;
}
}

const sm = new StateMachine();
console.log(sm.transition('start'));
console.log(sm.transition('invalid'));
console.log(sm.transition('pause'));
console.log(sm.transition('resume'));
console.log(sm.transition('stop'));
console.log(sm.transition('reset'));


Ответ: running running paused running stopped idle

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

const gen = generator();

const { value, done } = gen.return('early');

console.log(value, done);


Ответ: 'early', true

JavaScript test | #JavaScript
Please open Telegram to view this post
VIEW IN TELEGRAM
❗️Что будет на выходе:
const user = {
name: 'John',
age: 35,
};

for (const value in user) {
console.log(value);
}


Ответ:
name
age

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);

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

console.log('7');


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

JavaScript test | #JavaScript
Please open Telegram to view this post
VIEW IN TELEGRAM
❗️Что будет на выходе:
const promise = new Promise((resolve, reject) => {
setTimeout(() => reject(new Error('Error')), 1000);
});

promise
.then(result => console.log(result))
.then(result => console.log(result))
.catch(error => console.error(error.message))
.finally(() => console.log('Finally'));


Ответ: Finally

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 nums = [1, 2, 3];
const obj = { a: 1, b: 2, c: 3 };

function process(...args) {
const [first, ...rest] = args;
const { a, ...others } = obj;
return { first, rest, a, others };
}

const result = process(...nums);
console.log(result.first);
console.log(result.rest.length);
console.log(result.others.b);
console.log(Object.keys(result.others).join(''));
console.log(result.a === nums[0]);


Ответ: 1 2 2 bc true

JavaScript test | #JavaScript
Please open Telegram to view this post
VIEW IN TELEGRAM
❗️Что будет на выходе:
const array = [1, 2, 3, 4];
const result = array.reduceRight((acc, val) => acc - val);

console.log(result);

Ответ: -2

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