Open rauschma opened 6 years ago
It doesn't seem to deal with the BigInt type.
I am able to update primitive values properties and not getting any exception. for example
let str ='abc'; str.length=90;
Please try to test from your side as well
The exception is thrown only in the strict mode. Anyway, you're not changing the length — it only seems so.
@VenkateswaraT See the warning at the end of this section: https://exploringjs.com/impatient-js/ch_console.html#trying-out-code
Quote:
Consoles often run in non-strict mode
In modern JavaScript, most code (e.g., modules) is executed in strict mode. However, consoles often run in non-strict mode. Therefore, you may occasionally get slightly different results when using a console to execute code from this book.
@srcdes: BigInt is an ES2020 feature. It’ll be covered in the next edition. This is a preview of that content: https://2ality.com/2017/03/es-integer.html
The final example in this chapter of parseInt
appears to be an error. parseInt
converts its argument to a number, not string. I'm sure you knew that and meant to say number and pass '123.45' instead:
For example, parseInt() coerces its parameter to string (parsing stops at the first character that is not a digit):
typeof parseInt(123.45) "number"
Thanks for all your hard work and this awesome book.
Thank you for this book, it's the first time I have tried to learn JavaScript properly, rather than writing code until it works.
I feel that section 12.4.1.2 would make a stronger illustration about copying values if a third line is inserted into the code example:
Without it, the code example doesn't drive home the point that the values are now separate, and I had to test in the console to confirm it was the case.
@Jamoverjelly The book is correct, but the explanation is too short and easy to misunderstand. The next release will have a longer explanation: parseInt()
first coerces the number to a string and then parses that string and returns the result (a number).
@pbowyer That’s a very good point. Alas, finding a good example is difficult in this case: Even your additional line works the same with objects (if we compare them deeply/by value).
Adding a comment to my example may help:
const x = 123;
const y = x;
// `y` is the same as any other number 123
assert.equal(y, 123);
I am able to update primitive values properties and not getting any exception. for example
let str ='abc'; str.length=90;
Please try to test from your side as well