Get time
Async and Await in JavaScript
Async and await are used to handle asynchronous operations in JavaScript.
Async Function: Declaring a function as async
makes it return a promise.
Await: The await
keyword pauses execution until the promise resolves, making asynchronous code look synchronous.
Example:
async function fetchData() {
let response = await fetch('https://api.example.com/data');
let data = await response.json();
console.log(data);
}
fetchData();
This ensures fetchData
waits for data before proceeding.
numarray = [2,3,4,5,6,7] To get the minimum number in an array you can spread the array ie.
let minnum = Math.min(...numarray)
console.log(minnum) result is 2;