Sobes.tech

How to write a function that returns a Promise resolving after one second?

Middle+
163

What happens if the component type changes? Will the same key help preserve the state?

Middle+
163

What is the difference between rendering and drawing? What is the process called that compares the virtual and real DOM trees?

Middle+
162

const SomeElement = ({ hasData }) => { if (hasData) { return <div> <DataElement /> <SomeImportantElement /> </div> } return <div> <SomeImportantElement /> </div> }

Middle+
162

// 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]

Middle+
160

What is a closure in JavaScript? Where is it used in practice?

Middle+
159

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?

Middle+
159

Apart from methods and key types, what else does Map have that objects do not?

Middle+
157

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]} />;

Middle+
155

Provide an example of a closure. Have you used closures in React?

Middle+
152

Explain what the Event Loop is. What belongs to microtasks and macrotasks?

Middle+
152

What is the purpose of the 'unknown' type in TypeScript? How can the type be narrowed?

Middle+
151

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

Middle+
151

const a = {} a[1] = 'test' for ( ... )

Middle+
150

Tell about collections Map and Set in JavaScript — what do you know about them?

Middle+
150

What is the difference between sessionStorage and localStorage?

Middle+
150

What is the difference between the 'any' and 'unknown' types in TypeScript?

Middle+
150

What are the scopes of let/const and var? Is there another way to declare variables besides var, let, const?

Middle+
149

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)

Middle+
149

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} />

Middle+
146
/5