Sign in

Libre University uses your GitHub account. Signing in is only needed to sit a final test, so the score is kept on your profile.

Making decisions

1.[2p]

Why does this course tell you to use === and never ==?

Correct
The answer is: Loose equality is not transitive: `0 == "0"` and `0 == ""` are both true while `"" == "0"` is false, so arguments made with it can be invalid
The answer is: Loose equality is not transitive: `0 == "0"` and `0 == ""` are both true while `"" == "0"` is false, so arguments made with it can be invalid
The answer is: Loose equality is not transitive: `0 == "0"` and `0 == ""` are both true while `"" == "0"` is false, so arguments made with it can be invalid

2.[2p]

What does 3 > 2 > 1 evaluate to? Write true or false.

CorrectNot quite: false

3.[3p]

Which of these values are falsy?

Select all that apply

Correct
Correct
Correct
The answer is: The empty string `""`, `0`, `NaN`
The answer is: The empty string `""`, `0`, `NaN`

4.[3p]

Access is allowed when loggedIn && !banned. What is the correct condition for access denied?

Correct
The answer is: `!loggedIn || banned`
The answer is: `!loggedIn || banned`
The answer is: `!loggedIn || banned`

5.[2p]

const x = 0; What number does console.log(x ?? 10) print?

CorrectNot quite: 0

6.[2p]

In user && user.age >= 18, short circuiting is what stops user.age being read when user is undefined.

Correct
The answer is: True

7.[2p]

A parcel costs £3 under 1 kg, £5 under 5 kg, and £9 otherwise. Put the tests in the order the chain must use them.

  1. return 9;

  2. if (weight < 1) return 3;

  3. if (weight < 5) return 5;

Show the answer

b, a, c

8.[3p]

Match each expression to the value it produces.

  • 0 || "d"

  • 0 ?? 10

  • null ?? 10

  • 0 == "0"

  • "" == "0"

  • the number 0

  • the string "d"

  • true

  • the number 10

  • false

Show the answer

0 || "d": the string "d" 0 ?? 10: the number 0 null ?? 10: the number 10 0 == "0": true "" == "0": false

9.[2p]

What is the point of a guard clause?

Correct
The answer is: The exceptional cases are handled and returned first, so the main path stays at zero indentation and every rejection is visible at a glance
The answer is: The exceptional cases are handled and returned first, so the main path stays at zero indentation and every rejection is visible at a glance
The answer is: The exceptional cases are handled and returned first, so the main path stays at zero indentation and every rejection is visible at a glance