Skip to content

Instantly share code, notes, and snippets.

@baso53
Last active June 17, 2021 11:46
Show Gist options
  • Save baso53/1d2002e02c4bd6f0289de375bc94594b to your computer and use it in GitHub Desktop.
Save baso53/1d2002e02c4bd6f0289de375bc94594b to your computer and use it in GitHub Desktop.
JS Interview questions
await new Promise(resolve => setTimeout(() => resolve(5), 3000))
const func = () =>
Promise.resolve()
.then(() => new Promise(resolve => setTimeout(() => resolve(10), 3000)))
await func();
const promiseWithTimeout = (timeout) => new Promise(resolve => setTimeout(resolve, timeout));
const func1 = async () => await promiseWithTimeout(1000);
const func2 = async () => promiseWithTimeout(1000);
const func3 = () => promiseWithTimeout(1000);
const func4 = () =>
promiseWithTimeout(1000).then(() => {
promiseWithTimeout(1000);
});
await func1();
await func2();
await func3();
await func4();
console.log('done')
const promiseWithTimeout = (timeout) => new Promise(resolve => setTimeout(resolve, timeout));
promiseWithTimeout(1000)
.then(() => { promiseWithTimeout(1000) })
.then(() => promiseWithTimeout(1000))
.then(() => { promiseWithTimeout(1000) })
.then(() => promiseWithTimeout(1000))
.then(() => console.log('done'))
const array = ['1', '2', '3', '4'];
const appendString = ??
array.map(appendString('. place'));
// output: ['1. place', '2. place', '3. place', '4. place']
const a = {
name: 'Ivan'
};
const func1 = param => {
param = {
name: 'Josip'
};
}
const func2 = param => {
param.name = 'Petar';
}
func1();
func2();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment