Java Expert RE-Learning Javascript Part 2 - Operators
What do you thing, what does javascript do with the following ? "5" + 1 - result? "51" 5 + "1" - result? "51" "5" - 1 - result? 4 "5" == 5 - result? true null == undefined - result? true How did you do? I was bad at it, especially to realize that "5" + 1 and 5 + "1" would make the same result. Javascript tries always to do conversion whenever the types of operands dont match. Javascript is pretty easy-going language. It allows you to do many things, giving you a bit of additional freedom. BUT you have to be VERY careful, as you can imagine that in some cases, above mentioned freedom might cost you a lot of bugs :) So, summary of rules in Javascript about operators: If you give Javascript different types to operate with, it will start doing type conversion. The way it would do it is based on set of (often confusing) rules. It would check first the operator, and then try to convert opera...