sicp
sicp copied to clipboard
[sicpjs/1.1.6] Incorrect Solutions to Exercise 1.1 (`const` examples)
Both when running the example code in the inline IDE and also in the browser's console, the following expressions result in undefined being printed:
// exercise 1.1.6
const a = 3; // prints undefined
// exercise 1.1.7
const b = a + 1; // prints undefined
In the solutions, the values listed are 3 and 4 respectively. Which, given the results above, is incorrect.
The expressions that do result in 3 and 4 would be:
a = 3; // prints 3
b = a + 1; // prints 4
See attached screenshots for proof.
inline IDE results
console results
console corrected results
Yes, the solution should indicate that these two cases
// exercise 1.1.6 const a = 3; // prints undefined
// exercise 1.1.7 const b = a + 1; // prints undefined
should print undefined. Constant declarations don't produce any value in JavaScript. Chapter 1 doesn't mention this, but the excercise solution would be an opportunity to point this out.