setTimeout(() => {
console.log('setTimeout 1');
Promise.resolve().then(() => console.log('Promise 1'));
}, 0);
Promise.resolve().then(() => {
console.log('Promise 2');
setTimeout(() => console.log('setTimeout 2'), 0);
});
console.log('Sync');Ответ:
Please open Telegram to view this post
VIEW IN TELEGRAM
const person = {
name: "John",
greet: function() {
const getMessage = () => `Hello, ${this.name}`;
return getMessage();
}
};
console.log(person.greet());Ответ:
Please open Telegram to view this post
VIEW IN TELEGRAM
async function foo() {
console.log('Start');
await Promise.resolve().then(() => {
console.log('Inside Promise');
});
console.log('End');
}
foo();
console.log('Outside');Ответ:
Please open Telegram to view this post
VIEW IN TELEGRAM
const obj = {
name: 'Sarah',
getName() {
return this.name;
},
getNameArrow: () => {
return this.name;
}
};
const getName = obj.getName;
const getNameArrow = obj.getNameArrow;
console.log(obj.getName());
console.log(getName());
console.log(getNameArrow());
console.log(obj.getNameArrow());Ответ:
Please open Telegram to view this post
VIEW IN TELEGRAM
let a = 1;
let b = new Number(1);
let c = '1';
console.log(a == b);
console.log(a === b);
console.log(b == c);
Ответ:
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);Ответ:
Please open Telegram to view this post
VIEW IN TELEGRAM
const a = [1, 2, 3, 4];
console.log(a + "");
Ответ:
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);
Ответ:
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();
Ответ:
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());Ответ:
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
В программе:
💡 Паттерны и подводные камни View Transition API в React (Николай Шабалин, СберЗдоровье)
🧠 Глубокое погружение в архитектуру React Hooks (Максим Никитин, Rocket Science)
⚙️ Разбор FSD 2.1 на практике, без догм (Лев Челядинов, FSD Core team)
📚Подготовка к архитектурному интервью для фронтендеров (Игорь Антонов, Т-Банк)
📐Layout-паттерны за пределами Flexbox и CSS Grid (Саша Илатовский, Albato)
🎯 Все темы прикладные, с практикой и кейсами.
🔗 Подробности и билеты
P.S: Для подписчиков группы JavaScript Test скидка 500 р по промокоду
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);Ответ:
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);Ответ:
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);
Ответ:
JavaScript test | #JavaScript
Please open Telegram to view this post
VIEW IN TELEGRAM
function a() {
console.log(arguments[0]);
}
a([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);Ответ:
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'));Ответ:
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);Ответ:
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);
}Ответ:
age
Please open Telegram to view this post
VIEW IN TELEGRAM