❗️Что будет на выходе:
Ответ:['Alice', undefined, true, undefined]
JavaScript test | #JavaScript & Max
const user = {
profile: {
name: 'Alice',
social: null,
getDetails() {
return { verified: true };
}
}
};
const result = [
user?.profile?.name,
user?.profile?.social?.handle,
user.profile.getDetails?.()?.verified,
user?.nonExistent?.property
];
console.log(result);
Ответ:
JavaScript test | #JavaScript & Max
❗️Что будет на выходе:
Ответ:Hello, I'm Alice Hello, I'm undefined Goodbye from undefined
JavaScript test | #JavaScript & Max
const person = {
name: 'Alice',
greet() {
return `Hello, I'm ${this.name}`;
},
farewell: () => `Goodbye from ${this.name}`
};
const greetFn = person.greet;
const farewellFn = person.farewell;
console.log(person.greet());
console.log(greetFn());
console.log(farewellFn());
Ответ:
JavaScript test | #JavaScript & Max
❗️Что будет на выходе:
Ответ:A G C E B F D
JavaScript test | #JavaScript & Max
function task1() {
console.log('A');
setTimeout(() => console.log('B'), 0);
Promise.resolve().then(() => console.log('C'));
Promise.resolve().then(() => setTimeout(() => console.log('D'), 0));
Promise.resolve().then(() => console.log('E'));
setTimeout(() => console.log('F'), 0);
console.log('G');
}
task1();
Ответ:
JavaScript test | #JavaScript & Max
❗️Что будет на выходе:
Ответ:{ timeout: 0, retries: 3, logging: false, debug: true }
JavaScript test | #JavaScript & Max
function processConfig(config) {
const settings = {
timeout: config.timeout ?? 1000,
retries: config.retries ?? 3,
logging: config.logging ?? false,
debug: config.debug || true
};
return settings;
}
const userConfig = {
timeout: 0,
retries: null,
logging: false,
debug: false
};
console.log(processConfig(userConfig));
Ответ:
JavaScript test | #JavaScript & Max
❗️Что будет на выходе:
Ответ:
Invalid status
JavaScript test | #JavaScript & Max
function processData(data) {
try {
if (!data) {
throw new TypeError('Data is required');
}
if (data.status === 'error') {
throw new Error('Invalid status');
}
return data.value.toUpperCase();
} catch (err) {
if (err instanceof TypeError) {
return 'Type Error';
}
return err.message;
}
}
console.log(processData({ status: 'error', value: 'test' }));Ответ:
❗️Что будет на выходе:
Ответ:{ id: 42, name: 'Item', count: 3 }
JavaScript test | #JavaScript & Max
function analyze(...items) {
const [first, ...rest] = items;
const { length } = [...rest, 'bonus'];
const result = {
...first,
count: length,
};
console.log(result);
}
analyze({ id: 42, name: 'Item' }, 'a', 'b');Ответ:
JavaScript test | #JavaScript & Max
❗️Что будет на выходе:
Ответ:string
JavaScript test | #JavaScript & Max
let x = 5;
let result = typeof (x + "10");
console.log(result);
Ответ:
JavaScript test | #JavaScript & Max
❗️Что будет на выходе:
Ответ:2
JavaScript test | #JavaScript & Max
function createCounter() {
let count = 0;
return {
increment() {
count++;
return count;
},
decrement() {
count--;
return count;
},
getValue() {
return count;
}
};
}
const counter1 = createCounter();
const counter2 = createCounter();
counter1.increment();
counter1.increment();
counter2.increment();
counter1.decrement();
console.log(counter1.getValue() + counter2.getValue());
Ответ:
JavaScript test | #JavaScript & Max
❗️Что будет на выходе:
Ответ:I have been coding in <span> JavaScript </span> for <span>10</span> years
JavaScript test | #JavaScript & Max
function highlight(strings, ...values) {
return strings.reduce((result, str, i) => {
const value = values[i] ? `<span>${values[i]}</span>` : '';
return result + str + value;
}, '');
}
const language = 'JavaScript';
const years = 10;
const result = highlight`I have been coding in ${language} for ${years} years`;
console.log(result);
Ответ:
JavaScript test | #JavaScript & Max