How to write a function that returns a Promise resolving after one second?
Frontend
What happens if the component type changes? Will the same key help preserve the state?
What is the difference between rendering and drawing? What is the process called that compares the virtual and real DOM trees?
const SomeElement = ({ hasData }) => { if (hasData) { return <div> <DataElement /> <SomeImportantElement /> </div> } return <div> <SomeImportantElement /> </div> }
// The findUnique method is applied to the array, which returns a new array of unique elements, // i.e., those that appear only once in the original array, in the same order. // Implement the findUnique method so that it works like a regular array method [10, 5, 10, 1, 6, 6, 7, 9, 9, 10].findUnique(); // [5, 1, 7]
What is a closure in JavaScript? Where is it used in practice?
What will happen if the dependencies array is not specified in useEffect? If you add count to the dependencies array and press the button, will the cleanup function be triggered?
Apart from methods and key types, what else does Map have that objects do not?
import React, { useState, useEffect, useRef, useContext, useReducer, useMemo, me const someFunc = (arr) => { return [...arr].sort((a, b) => a - b); }; const LazyInit = (props) => { const [arr, setArr] = useState(someFunc(props.arr)); const onClick = () => { setArr((prev) => prev.concat(prev.length + 1)) } return ( <> <button onClick={onClick}> Increment </button> <ul> {arr.map((n, index) => <li key={index}>{n}</li>)} </ul> </> ) } export default () => <LazyInit arr={[1, 2, 3]} />;
Provide an example of a closure. Have you used closures in React?
Explain what the Event Loop is. What belongs to microtasks and macrotasks?
What is the purpose of the 'unknown' type in TypeScript? How can the type be narrowed?
const doSomething = (ms) => { return new Promise((resolve, reject) => { setTimeout(() => { if (Math.random() <= 0.5) { reject("error"); } else { resolve(ms); } }, ms); }); }; const getDelay = () => { let rand = 1000 + Math.random() * 2000; return Math.floor(rand); }; const p1 = doSomething(getDelay()); const p2 = doSomething(getDelay()); const p3 = doSomething(getDelay()); const p4 = doSomething(getDelay());
const a = {} a[1] = 'test' for ( ... )
Tell about collections Map and Set in JavaScript — what do you know about them?
What is the difference between sessionStorage and localStorage?
What is the difference between the 'any' and 'unknown' types in TypeScript?
What are the scopes of let/const and var? Is there another way to declare variables besides var, let, const?
setTimeout(() => { console.log("timeOut"); }, 0) console.log(1); new Promise(resolve => { console.log("Promise"); setTimeout(() => { console.log("777"); resolve() }, 0) }).then(() => { console.log("then1"); }) .then(console.log('tratata')) .then(() => console.log("then2"); }) console.log(4); setTimeout(() => { console.log("timeOut2"); }, 0)
const func = obj.sayHi() const boundFuns = func.bind(obj) boundFuns() ------------------- const submit = (el) => () => { log(el); } arr.map(el => <button onClick={submit(el)}/>) const param = useMemo(() => a + b) return <Child value={param} />