What is the main purpose of the await keyword within an async function?
4 phương ánCó giải thích
Các phương án trả lời
Chọn một phương ánLời giảiChọn phương án để mở
Đáp án đúng: "To pause the execution of the async function until the Promise it's waiting for is resolved or rejected.". Từ khoá await chỉ dùng trong hàm async (hoặc ở cấp cao nhất của module): nó tạm dừng phần thân còn lại của hàm đó cho tới khi Promise đứng sau nó ổn định, nếu resolve thì biểu thức await trả về giá trị, nếu reject thì ném lỗi để try/catch bắt; trong lúc chờ, luồng chính không bị chặn mà vẫn xử lý việc khác qua event loop (vòng lặp sự kiện). "To return a new Promise object." mô tả từ khoá async chứ không phải await, vì chính hàm async luôn trả về một Promise. "To immediately execute the next line of code without waiting." ngược hẳn với await, đó là hành vi khi gọi một hàm trả Promise mà không await nó. "To define a synchronous block of code" sai vì await không tạo khối mã đồng bộ, mã chỉ trông tuần tự còn bản chất vẫn bất đồng bộ.
Cùng phần 8
Which method is most commonly used in a React app to fetch data from a server?Có lời giảiCâu hỏiconst jsonServer = require('json-server'); const server = jsonServer.create(); const router = jsonServer.router('data.json'); const port = 3000; server.use(router); server.listen(port, () => { console.log('JSON server is running on port ${port}'); });
What is the above code used for?Có lời giảiCâu hỏiWhat is the difference between the HTTP response codes 401 and 403?Có lời giảiCâu hỏiCả 33 câu của chủ đề33 câu