Question

I am following the example from coffeescript cookbook

and I am playing a bit with this example: http://jsfiddle.net/andilab/N8DP3/2/

normal_false = 1<2<2 #false -> is NOT printed

normal_true  = 1<2<3 #true -> is printed

wondering why false is not printed until used with JSON.stringify, is it matter of coffescript or JSFiddle or jQuery?

Was it helpful?

Solution

This is caused by the use of jQuery's append function.

Append calls various things and at some point calls buildFragment to turn the argument provided into an HTML fragment to add.

In this function is the following:

if ( elem || elem === 0 ) {
    ... //Most of the code that generates stuff
}

elem in this case will be false and so it skips over it.

I assumed this line is defined to catch "undefined" things being passed in and just happens to catch false too. Further than this I can't say why the code is like this but its that line of code that does it.

Reference: http://code.jquery.com/jquery-2.1.0.js

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top