There are two finer points of the language that may be confusing sometimes even to experienced developers.
The first one is type coercion, which is an automatism to align values for the task at hand. For example, a logical operator will coerce any value to a boolean for the sake of evaluation. An empty string is falsy, a string containing characters isn't. There's quite a complex set of rules to this, and it makes the language easily confusing.
That brings us to the second one, which is operator precedence. I'll spare you the details, it's just that some operators are processed prior to other ones.
Especially in combination, these two points lend themselves to a many WTF-moments when writing JavaScript.
Software dev at Netflix | DC techie | Conference speaker | egghead Instructor | TC39 Educators Committee | Girls Who Code Facilitator | Board game geek | @laurieontech on twitter
There are two finer points of the language that may be confusing sometimes even to experienced developers.
The first one is type coercion, which is an automatism to align values for the task at hand. For example, a logical operator will coerce any value to a boolean for the sake of evaluation. An empty string is falsy, a string containing characters isn't. There's quite a complex set of rules to this, and it makes the language easily confusing.
That brings us to the second one, which is operator precedence. I'll spare you the details, it's just that some operators are processed prior to other ones.
Especially in combination, these two points lend themselves to a many WTF-moments when writing JavaScript.
No question. And that’s the former is what most of this post focuses on. It resolves each side of the operator to a Boolean and operates accordingly.