December 2017
Beginner
372 pages
10h 32m
English
If you have a number in quotes, JavaScript will determine it as a string but, if you do a comparison in an if statement to a literal number, then JavaScript will automatically try to convert the string into a number and perform the comparison:
var result = '1';console.log(result == 1); // returns trueconsole.log(result === 1); // returns false
Now, this can be something which you may or may not have expected to happen, because sometimes we may not want JavaScript to do these type of comparisons. For small applications, you can make sure that you are passing proper types, but that's not so easy in the case of large-scale applications. One solution would be to use === rather than ==, which makes JavaScript not coerce the ...
Read now
Unlock full access