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.

Values, names and types

1.[2p]

Why does 0.1 + 0.2 === 0.3 evaluate to false?

Correct
The answer is: One tenth has no exact binary representation, so the stored values are slightly off and their rounded sum is a different double from the nearest double to 0.3
The answer is: One tenth has no exact binary representation, so the stored values are slightly off and their rounded sum is a different double from the nearest double to 0.3
The answer is: One tenth has no exact binary representation, so the stored values are slightly off and their rounded sum is a different double from the nearest double to 0.3

2.[2p]

What string does typeof null return? Write it without quotes.

CorrectNot quite: object

3.[2p]

"5" - 3 evaluates to the number 2, while "5" + 3 evaluates to the string "53". Why do the two coerce in opposite directions?

Correct
The answer is: `+` has a string meaning, concatenation, so the number becomes a string; `-` has no string meaning, so the string becomes a number
The answer is: `+` has a string meaning, concatenation, so the number becomes a string; `-` has no string meaning, so the string becomes a number
The answer is: `+` has a string meaning, concatenation, so the number becomes a string; `-` has no string meaning, so the string becomes a number

4.[2p]

What does 1 + 2 + "3" evaluate to? Write the result without quotes.

CorrectNot quite: 33

5.[1p]

NaN === NaN evaluates to false, which is why Number.isNaN(x) exists.

Correct
The answer is: True

6.[2p]

What does 2 ** 10 % 100 evaluate to?

CorrectNot quite: 24

7.[2p]

Which of these are true of const?

Select all that apply

Correct
Correct
The answer is: A name declared with `const` cannot be rebound to another value, Reaching for `const` first and switching to `let` only when reassignment is needed is the working habit
The answer is: A name declared with `const` cannot be rebound to another value, Reaching for `const` first and switching to `let` only when reassignment is needed is the working habit

8.[2p]

Put these steps in the order the machine performs them when running count = count + 1.

  1. Add 1 to that value

  2. Look up the value currently held by count

  3. Bind the name count to that result

Show the answer

b, c, a

9.[3p]

Match each expression to the value it produces.

  • 7 / 2

  • "2" + "3"

  • Number("abc")

  • 1 / 0

  • "hello".length

  • 5

  • 3.5

  • NaN

  • Infinity

  • the string "23"

Show the answer

7 / 2: 3.5 "2" + "3": the string "23" Number("abc"): NaN 1 / 0: Infinity "hello".length: 5