Skip to content

Type conversions on strings #1646

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

Closed
CyberMew opened this issue Dec 2, 2019 · 2 comments
Closed

Type conversions on strings #1646

CyberMew opened this issue Dec 2, 2019 · 2 comments

Comments

@CyberMew
Copy link
Contributor

CyberMew commented Dec 2, 2019

https://javascript.info/type-conversions

This only happens when at least one of the arguments is a string. Otherwise, values are converted to numbers.

This is confusing as it implies that as long as an expression contains a string, the whole expression will be a string. However based on the example 4 + 5 + "px" which gives 9px, this is not the case. I understand the "arguments" to be for +, but it can also be read as arguments for the alert() function. I think being a little more explicit is better here. Maybe state something like only the immediate left and right operands of the + operator is affected? And the expression is evaluated from left to right (or by operator precedence)?

@CyberMew
Copy link
Contributor Author

CyberMew commented Dec 2, 2019

Just saw https://javascript.info/operators after type-conversions, perhaps operators should come first? After all we need operators to use some of the type conversions.

iliakan added a commit that referenced this issue Dec 2, 2019
@iliakan iliakan closed this as completed Dec 2, 2019
@iliakan
Copy link
Member

iliakan commented Dec 2, 2019

Good catch! Thanks!

jchue pushed a commit to jchue/en.javascript.info that referenced this issue Dec 7, 2019
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

2 participants