Last active
June 17, 2021 11:46
-
-
Save baso53/1d2002e02c4bd6f0289de375bc94594b to your computer and use it in GitHub Desktop.
JS Interview questions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
await new Promise(resolve => setTimeout(() => resolve(5), 3000)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const func = () => | |
Promise.resolve() | |
.then(() => new Promise(resolve => setTimeout(() => resolve(10), 3000))) | |
await func(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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')) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const array = ['1', '2', '3', '4']; | |
const appendString = ?? | |
array.map(appendString('. place')); | |
// output: ['1. place', '2. place', '3. place', '4. place'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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