Identify JavaScript as a language that utilizes an event loop model
event loop
model of execution.
Identify JavaScript as a single threaded language
Single-threaded execution
: Only one command can be processed at a time.
Describe the difference between asynchronous and synchronous code
Synchronous
: Means there is an inherent order among the commands and this order of execution is guaranteed. Basically will evaluate top, down - left, right.
Asynchronous
: No guarantee in the total order that commands are executed.
Execute the asynchronous function setTimeout with a callback.
function foo(food1, food2) {
console.log(food1 + " for breakfast");
console.log(food2 + " for lunch");
}
setTimeout(foo, 2000, "pancakes", "couscous");
Given the function predict the output of “asyncy(callback);”
Use setInterval to have a function execute 10 times with a 1 second period. After the 10th cycle, clear the interval.
Write a program that accepts user input using Node’s readline module
const askGuess = () => {
rl.question(
"Berber asks: Can you guess how many snacks I want to eat right now? ",
(answer) => {
!checkGuess(Number(answer)) ? askGuess() : rl.close();
}
);
};