Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chapter: Values #7

Open
rauschma opened this issue Jun 26, 2018 · 9 comments
Open

Chapter: Values #7

rauschma opened this issue Jun 26, 2018 · 9 comments

Comments

@rauschma
Copy link
Owner

No description provided.

@ghost
Copy link

ghost commented Jul 17, 2019

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
image

@ghost
Copy link

ghost commented Mar 4, 2020

It doesn't seem to deal with the BigInt type.

@minemax-ua
Copy link

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
image

The exception is thrown only in the strict mode.
Anyway, you're not changing the length — it only seems so.

@rauschma
Copy link
Owner Author

rauschma commented Mar 4, 2020

@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.

@rauschma
Copy link
Owner Author

rauschma commented Mar 4, 2020

@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

@Jamoverjelly
Copy link

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.

@pbowyer
Copy link

pbowyer commented Aug 19, 2021

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:

image

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.

@rauschma
Copy link
Owner Author

rauschma commented Jan 2, 2022

@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).

@rauschma
Copy link
Owner Author

rauschma commented Jan 2, 2022

@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);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants