Alternatives to If (Unless, Provided That, As Long As, In Case)

Alternatives to If (Unless, Provided That, As Long As, In Case) — Bài Tập 4

/ 10

Alternatives to If (Unless, Provided That, As Long As, In Case) — Bài Tập 4

Luyện tập ngữ pháp tiếng Anh chủ đề Alternatives to If (Unless, Provided That, As Long As, In Case) qua 10 câu hỏi trắc nghiệm. Trả lời đúng ít nhất 70% để hoàn thành bài.

Other conditional conjunctions: unless (if not), provided that, as long as (only if), in case (as a precaution).

B2 · Upper Intermediate TOEIC 605–780 IELTS 5.5–6.5 Clauses & Conditionals
10 câu hỏi Điểm qua: 70% Bài 4

Hướng dẫn làm bài

  • Đọc kỹ từng câu hỏi và chọn đáp án đúng nhất.
  • Bài thi không giới hạn thời gian — bạn có thể làm theo tốc độ của mình.
  • Nhấn Nộp bài khi đã hoàn thành để xem kết quả và giải thích chi tiết.

Login to save your result

You can take this test without logging in, but your result won't be saved. Login to track your progress.

  1. 1

    You want to add an item to an array `cart` only if `item` is not null. Which short-circuiting expression is suitable?

  2. 2

    You want to submit a form only if `isValidForm` is true. Which short-circuiting expression is suitable?

  3. 3

    You are building a system that needs to handle different types of user input (e.g., keyboard events, mouse clicks, touch gestures). Instead of using `if-else if` to check the input type and call the specific handler, you define a common `IInputHandler` interface and have specific handler classes implement it. What is this an application of?

  4. 4

    You want to display a loading spinner only if `isLoading` is true. Which short-circuiting expression is suitable?

  5. 5

    Which of the following is a common use case for a `switch` statement with string values?

  6. 6

    A system needs to support various sorting algorithms (e.g., QuickSort, MergeSort, BubbleSort). The choice of algorithm depends on factors like data size and expected distribution. Which design pattern would allow you to dynamically select and apply a sorting algorithm without modifying the client code that uses it, replacing a large `if-else if` structure?

  7. 7

    To map HTTP status codes to descriptive messages (e.g., 200 to 'OK', 404 to 'Not Found'), which data structure is most efficient for replacing a large `switch` statement?

  8. 8

    In a language with optional chaining, if `user` is an object, but `user.profile` is `undefined`, what will `user?.profile?.getAvatarUrl()` evaluate to?

  9. 9

    You are refactoring a system where a complex `if-else if` structure is used to manage different stages of a document approval process (e.g., 'Draft', 'Review', 'Approved', 'Rejected'). The available actions (e.g., `submit()`, `approve()`, `reject()`) and their behavior change significantly depending on the current stage. Which design pattern is best suited to model this workflow and eliminate conditional logic based on state?

  10. 10

    A function `validateUser(user)` needs to ensure `user` is an object and has a `name` property. If not, it should return `false` immediately. How would you use guard clauses for this?