Alternativas ao If (Unless, Provided That, As Long As, In Case)

Alternativas ao If (Unless, Provided That, As Long As, In Case) — Exercise 1

/ 10

Alternativas ao If (Unless, Provided That, As Long As, In Case) — Exercise 1

Practice English grammar topic Alternativas ao If (Unless, Provided That, As Long As, In Case) with 10 multiple-choice questions. Answer at least 70% correctly to complete the test.

Outras conjunções condicionais: unless (a menos que), provided that (desde que), as long as (contanto que), in case (caso).

B2 · Intermédio Superior TOEIC 605–780 IELTS 5,5–6,5 Orações e Condicionais
10 questions Nota mínima: 70% Test 1

How to take the test

  • Read each question carefully and select the best answer.
  • The test is not timed — you can complete it at your own pace.
  • Click Enviar Teste when finished to see your score and detailed explanations.

Entre para salvar seu resultado

Você pode fazer este teste sem entrar, mas o resultado não será salvo. Entrar para acompanhar seu progresso.

  1. 1

    A function `calculateDiscount(price, coupon)` needs to return 0 if `coupon` is null or invalid. What is the best way to implement this using a guard clause?

  2. 2

    What is the result of `const result = (10 > 5) ? 'Greater' : 'Smaller';`?

  3. 3

    In a language with optional chaining, if `data` is an array of objects, and you want to safely access the `name` property of the first element, which might not exist, how would you write it?

  4. 4

    To provide a default value for a date variable `eventDate` to today's date if it's null or undefined, which operator is most suitable?

  5. 5

    A function `fetchData(id)` should return an empty array immediately if `id` is negative. How would you implement this using a guard clause?

  6. 6

    Consider the code: `let status = (score > 90) ? 'Excellent' : 'Good';`. What is 'Excellent' if score is 95?

  7. 7

    You want to ensure a function parameter `name` always has a value, defaulting to 'Anonymous' if it's not provided or is an empty string. Which operator can help achieve this concisely?

  8. 8

    You are building a system that needs to apply different validation rules (e.g., `EmailValidator`, `PasswordValidator`, `AgeValidator`) based on the type of data being validated. Instead of using `if-else if` to select the validator, you store validator instances in a map where keys are data types and values are validator objects. What is this an example of?

  9. 9

    You are building a system that needs to retrieve environment variables. If an environment variable is not set, you want to use a default value. Which operator is ideal for this, especially if an empty string is a valid configuration?

  10. 10

    When is it generally preferable to use a `switch` statement over a long `if-else if` ladder?